diff --git a/changelog/12011.bugfix.rst b/changelog/12011.bugfix.rst new file mode 100644 index 000000000..5b755ade3 --- /dev/null +++ b/changelog/12011.bugfix.rst @@ -0,0 +1 @@ +Fixed a regression in 8.0.1 whereby ``setup_module`` xunit-style fixtures are not executed when ``--doctest-modules`` is passed. diff --git a/testing/test_doctest.py b/testing/test_doctest.py index c91ec31cd..32897a916 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -878,6 +878,25 @@ class TestDoctests: result = pytester.runpytest(p, "--doctest-modules") result.stdout.fnmatch_lines(["*collected 1 item*"]) + def test_setup_module(self, pytester: Pytester) -> None: + """Regression test for #12011 - setup_module not executed when running + with `--doctest-modules`.""" + pytester.makepyfile( + """ + CONSTANT = 0 + + def setup_module(): + global CONSTANT + CONSTANT = 1 + + def test(): + assert CONSTANT == 1 + """ + ) + result = pytester.runpytest("--doctest-modules") + assert result.ret == 0 + result.assert_outcomes(passed=1) + class TestLiterals: @pytest.mark.parametrize("config_mode", ["ini", "comment"])