Skip to content

Give duplicated test method names distinct names so both run - #263

Merged
mmore500 merged 4 commits into
jeetsukumaran:mainfrom
dylanpulver:tests/unshadow-duplicate-test-names
Nov 3, 2026
Merged

mmore500 merged 4 commits into
jeetsukumaran:mainfrom
dylanpulver:tests/unshadow-duplicate-test-names

Conversation

@dylanpulver

Copy link
Copy Markdown
Contributor

Eleven test methods share a name with an earlier method in the same class, so Python keeps only the last definition and the earlier one never runs. tests/unittests tests/smoketests goes from 1152 collected to 1161, with the same four pre-existing failures before and after (three in test_datamodel_split_bitmasks.py, one in test_paup.py, all needing an external PAUP* binary).

Nine renames. In each case the body says which name is wrong:

  • test_dataio_newick_reader_rooting.py, in all four interpreter classes: the first of each pair parses "&u" but is named ..._ucase, while its neighbour parses "&U". Renamed to ..._lcase, matching the test_with_rooted_token_lcase already present in each class.
  • test_datamodel_tree_structure_and_iteration.py: the second test_leaf_node_iter_filtered calls ageorder_node_iter and sits in the Age-Order section next to test_ageorder_node_iter_unfiltered.
  • test_datamodel_charmatrix.py: the second test_setitem_by_idx_not_in_namespace subscripts by label and expects KeyError, not by index expecting IndexError; and the second test_fill_taxa calls pack(), inside CharacterMatrixFillAndPackTestCase.
  • test_datamodel_tree_list.py: the second test_remove calls tlist.reverse().
  • test_dataio_tokenizer.py: the second test_comments captures comments into a dict rather than skipping them.

Two deletions, where the definition that runs already covers the dead one:

  • test_phylogenetic_distance_matrix.py: the two bodies are byte-identical.
  • test_datamodel_tree_construction_copying_and_identity.py: the dead one is a strict prefix of the one that runs.

All nine revived tests pass. I left tests/smoketests/test_container.py alone deliberately: it has the same duplicate-name problem for test_pop and test_index, but reviving test_pop surfaces a separate question about NormalizedBitmaskDict() with no arguments, which warns that other or fill_bitmask must be given and then raises TypeError in least_significant_set_bit. That looked like yours to decide rather than something to fold in here.

Eleven test methods share a name with an earlier method in the same class, so
Python keeps only the last definition and the earlier one never runs. The
collected count goes from 1152 to 1161.

Nine are renames of the MISNAMED definition, which the body makes unambiguous:

- test_dataio_newick_reader_rooting.py, in all four interpreter classes: the
  first of each pair parses "&u" and is named ...ucase, while its neighbour
  parses "&U". Renamed to ...lcase, matching test_with_rooted_token_lcase
  already in each class.
- test_datamodel_tree_structure_and_iteration.py: the second
  test_leaf_node_iter_filtered calls ageorder_node_iter and sits in the
  Age-Order section beside test_ageorder_node_iter_unfiltered.
- test_datamodel_charmatrix.py: the second test_setitem_by_idx_not_in_namespace
  subscripts by LABEL and expects KeyError; the second test_fill_taxa calls
  pack(), in CharacterMatrixFillAndPackTestCase.
- test_datamodel_tree_list.py: the second test_remove calls tlist.reverse().
- test_dataio_tokenizer.py: the second test_comments captures comments into a
  dict rather than skipping them.

Two are deletions, where the surviving definition already covers the dead one:

- test_phylogenetic_distance_matrix.py: the two bodies are identical.
- test_datamodel_tree_construction_copying_and_identity.py: the dead one is a
  strict prefix of the one that runs.
@mmore500

mmore500 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Good catch thanks @dylanpulver

We should add this to our lint rules so it doesn't happen. Would you be up to add that to this PR?

Also, please disclose agentic AI use. I assume this PR is agentic in nature?

@codecov-commenter

codecov-commenter commented Nov 3, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.59%. Comparing base (75ab706) to head (8ad33ba).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #263      +/-   ##
==========================================
+ Coverage   89.16%   89.59%   +0.42%     
==========================================
  Files         116      116              
  Lines       13406    13386      -20     
==========================================
+ Hits        11954    11993      +39     
+ Misses       1452     1393      -59     
Flag Coverage Δ
unittests 89.59% <100.00%> (+0.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mmore500 mmore500 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Some suggestions

self.assertNotEqual(tree1.label, "tree2")
self.assertNotEqual(tree1.label, tree2.label)

def test_construction_from_given_seed_node(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why deletions? Are these just straight up duplications of another test?

obs_maxt = self.pdm.max_pairwise_distance_taxa(is_weighted_edge_distances=True)
self.assertEqual(set(obs_maxt), maxt)

def test_max_pairwise_weighted_distance_taxa(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

- rooting tests: keep the "&u" tests as ...ucase and rename the "&U" twins to
  ...Ucase, as requested, instead of renaming the lowercase ones to lcase.
- charmatrix: test_pack -> test_pack_pads_taxa_to_equal_length.
- lint.sh: select F811, which is the rule that catches this whole class. Scoped
  to tests/unittests, since that tree is now clean.

Enabling F811 surfaced three more in the same tree, fixed here:

- a second `class TestCharacterMatrixTaxa` replaced the first, so its
  test_basic_taxa (poll_taxa coverage) never ran. The second one tests purging,
  so it is now TestCharacterMatrixPurgeTaxonNamespace.
- five duplicate `import sys` / `import os` lines across four test modules.

tests/unittests + tests/smoketests: 1152 collected before the branch, 1162 now,
with the same four pre-existing failures either side.

@mmore500 mmore500 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last cleanup!

Comment thread lint.sh Resolved
@mmore500

mmore500 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Also, @dylanpulver can you follow up on the two review comments still open?

(Assuming that this is agentic, let me know if you are human and I should be a little less directive.)

Comment thread lint.sh Resolved

@mmore500 mmore500 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks @dylanpulver

@mmore500
mmore500 merged commit 3192f15 into jeetsukumaran:main Nov 3, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants