question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inconsistent behavior report vs collect in Pytest 7 (corner case)

See original GitHub issue

test 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:closed
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Mar 4, 2022

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”

0reactions
asottilecommented, Mar 4, 2022

flake8 (via pyflakes) catches this for instance

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found