Skip to content

pytest 8.0.0 ignores autouse fixtures in doctest modules when collecting packages #11929

@mgedmin

Description

@mgedmin

pyspacewar has a test suite written back when I still thought doctest modules were neat. It uses --doctest-modules and relies on some module-global setup/teardown specified in a @pytest.fixture(autouse=True).

This broke with the pytest 8.0.0 release. If I run

pytest src/pyspacewar/tests/ --setup-show 

I can see that the autouse fixtures defined in my conftest.py are being called, but the autouse fixture in src/pyspacewar/tests/test_main.py (fake_game_ui) is not. This breaks the tests or makes them hang:

src/pyspacewar/tests/test_main.py src/pyspacewar/tests/test_main.py::pyspacewar.tests.test_main.doctest_main (fixtures used: setUp) 

Curiously, if I run just a single file or all the test files in the directory, this doesn't happen:

pytest src/pyspacewar/tests/*.py --setup-show 

shows

... src/pyspacewar/tests/test_main.py SETUP M fake_game_ui src/pyspacewar/tests/test_main.py::pyspacewar.tests.test_main.doctest_main (fixtures used: fake_game_ui, setUp). TEARDOWN M fake_game_ui ... 

which is also what pytest 7.4.4 used to do.

I've verified by pip install "pytest<8" and pip install -U pytest that pytest being 7.4.4 vs 8.0.0 is the only difference between a working and a not-working tox environment. A full pip list is here:

Package Version ---------- ---------- iniconfig 2.0.0 mock 5.1.0 packaging 23.2 pip 23.2.1 pluggy 1.4.0 pygame 2.5.2 pyspacewar 1.2.0.dev0 pytest 8.0.0 

OS: Ubuntu 23.10.

I have not yet tried to produce a separate minimal example, but you should be able to quickly reproduce this if you

git clone https://github.com/mgedmin/pyspacewar tox -e py312 --notest .tox/py312/bin/pip install -U pytest # because I pinned to <8 as a workaround for now .tox/py312/bin/pytest src/pyspacewar/tests/ --setup-show 

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: doctestsrelated to the doctests builtin plugintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions