testing: add a regression test for `setup_module` + `--doctest-modules`

Refs #12011 (only fails on 8.0.1, not main).
This commit is contained in:
Ran Benita 2024-02-19 20:54:49 +02:00
parent 998fee1679
commit a37cff3ca8
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1 @@
Fixed a regression in 8.0.1 whereby ``setup_module`` xunit-style fixtures are not executed when ``--doctest-modules`` is passed.

View File

@ -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"])