Skip to content

Fix module fixtures with --doctest-modules#14540

Open
minbang930 wants to merge 1 commit into
pytest-dev:mainfrom
minbang930:fix-14533-doctest-module-fixtures
Open

Fix module fixtures with --doctest-modules#14540
minbang930 wants to merge 1 commit into
pytest-dev:mainfrom
minbang930:fix-14533-doctest-module-fixtures

Conversation

@minbang930
Copy link
Copy Markdown

@minbang930 minbang930 commented Jun 1, 2026

Summary

  • Fix fixture registration when --doctest-modules collects a Python module before the normal module collector.
  • Key parsed fixture holders by their visibility anchor, so normal tests get module-scoped FixtureDefs without relaxing node-based scoping.
  • Add a regression test, changelog entry, and AUTHORS entry.

Closes #14533.

Test plan

  • PYTHONPATH=src python /tmp/pytest-14533-repro/run_checkout_pytest.py -q testing/test_doctest.py::TestDoctests::test_module_fixture_available_to_normal_test_with_doctestmodules testing/test_doctest.py::TestDoctests::test_doctestmodule_with_fixtures testing/test_doctest.py::TestDoctests::test_doctestmodule_three_tests testing/test_doctest.py::TestDoctestAutoUseFixtures37 passed in 0.75s
  • PYTHONPATH=src python /tmp/pytest-14533-repro/run_checkout_pytest.py -q testing/test_conftest.py::test_conftest_fixture_scoping_with_testpaths_outside_rootdir testing/test_conftest.py::test_conftest_fixture_from_ancestor_above_rootdir testing/deprecated_test.py::TestFixtureNodeidDeprecations6 passed in 0.14s
  • PYTHONPATH=src python /tmp/pytest-14533-repro/run_checkout_pytest.py -q testing/python/fixtures.py::TestFixtureManagerParseFactories::test_parsefactories_conftest testing/python/fixtures.py::TestFixtureManagerParseFactories::test_parsefactories_conftest_and_module_and_class testing/python/fixtures.py::TestFixtureManagerParseFactories::test_parsefactories_relative_node_ids3 passed in 0.10s
  • git diff --check
  • python -m compileall -q src/_pytest/fixtures.py testing/test_doctest.py
  • python -m ruff check src/_pytest/fixtures.py testing/test_doctest.py
  • python -m ruff format --check src/_pytest/fixtures.py testing/test_doctest.py

AI assistance

OpenAI Codex helped reproduce the bug, draft the regression test, and prepare the initial patch. I reviewed the diff, checked the fixture scoping risk, added the changelog and AUTHORS entries, reran the targeted tests, and take responsibility for the change.

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Add closes #14533 to the PR description and commit message.
  • Credit the AI agent in a Co-authored-by commit trailer.
  • Create a changelog file in changelog/.
  • Add myself to AUTHORS in alphabetical order.

pytest can collect the same Python module through DoctestModule and Module. FixtureManager skipped the second parse because it keyed parsed holders only by module object.

Key parsed holders by visibility anchor too. Normal tests get FixtureDefs anchored to their Module collector, and node-based fixture scoping remains unchanged.

Closes pytest-dev#14533.

Co-authored-by: OpenAI Codex <codex@openai.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enabling doctest-modules causes fixture to not be found

1 participant