inconsistent behavior report vs collect in Pytest 7 (corner case)
See original GitHub issuetest example should include two test functions having the same name (this is just an example):
def test_1():
assert False
def test_2():
assert True
def test_1():
assert True
Pytest 7:
platform linux -- Python 3.10.2, pytest-7.0.1, pluggy-1.0.0 -- /somedir/python
cachedir: .pytest_cache
rootdir: somedir, configfile: setup.cfg
collected 2 items
test.py::test_1 PASSED [ 50%]
test.py::test_2 PASSED [100%]
Pytest 6:
platform linux -- Python 3.10.2, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /somedir/python
cachedir: .pytest_cache
rootdir: somedir, configfile: setup.cfg
collected 2 items
test.py::test_2 PASSED [ 50%]
test.py::test_1 PASSED [100%]
With Pytest 7 tests are ordered by definition ignoring possible re-definition. I can’t find documented behavior for duplicated test functions, so feel free to close this ticket if this is something not supported.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Pytest 3.7 not collecting tests on mixed Package and Modules
Hi! I've found an issue with pytest 3.7 while collecting tests on a mixed Python packages and modules folder structure, which worked ...
Read more >Full pytest documentation
How to write and report assertions in tests ... Scope: sharing fixtures across classes, modules, packages or session · Teardown/Cleanup (AKA Fixture ...
Read more >Deprecations and Removals — pytest documentation
This page lists all pytest features that are currently deprecated or have been removed in past major releases. The objective is to give...
Read more >How to write and report assertions in tests - Pytest
raises() is likely to be better for cases where you are testing exceptions your own code is deliberately raising, whereas using @pytest.mark.xfail with...
Read more >pytest Documentation
Exit code 0 All tests were collected and passed successfully. Exit code 1 Tests were collected and run but some of the tests...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

in pytest 6 there was an error prone attempt to find the location of the test by loading the tests’ source and traversing through the ast and source
in pytest 7 the ordering is what cpython tells us it is (due to dictionaries maintaining insertion order and the module ~essentially being an object with
__dict__having its members)the change in behaviour “makes sense” here – but the code seems wrong (duplicate definitions are going to clobber themselves) – so to me this seems “garbage in garbage out”
flake8 (via pyflakes) catches this for instance