Duplicate names for tests results in some tests being skipped.
When a function or class is defined multiple times in the same scope the last definition overwrite all the previous ones. This is true for variable assignments in general as well as tests more specifically.
Test runners such as pytest or the built-in unittest package can only detect and run the tests that are defined in the test files - so if a file contains a duplicate test name then the earlier ones will not be available to the test runner and will therefore not be ran:
So three tests were written. Lets run them:
Three tests were written but only one test was found in the file and therefore only one test was ran.
If our GitHub code review bot spots this issue in your pull request it gives this advice:
1 | + | class TestFeature(unittest.TestCase): | |
2 | + | def test_feature(self): | |
3 | + | ... | |
4 | + | ||
5 | + | def test_feature(self): |
Duplicate names for tests results in some tests being skipped.
Read more- | def test_feature(self): |
+ | def test_feature_two(self): |
6 | + | ... |