Skip to content

Commit 8a410d0

Browse files
authored
Merge pull request #12013 from bluetech/doctest-test
testing: add a regression test for `setup_module` + `--doctest-modules`
2 parents 95f21f9 + a37cff3 commit 8a410d0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

changelog/12011.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a regression in 8.0.1 whereby ``setup_module`` xunit-style fixtures are not executed when ``--doctest-modules`` is passed.

testing/test_doctest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,25 @@ def test_foo():
878878
result = pytester.runpytest(p, "--doctest-modules")
879879
result.stdout.fnmatch_lines(["*collected 1 item*"])
880880

881+
def test_setup_module(self, pytester: Pytester) -> None:
882+
"""Regression test for #12011 - setup_module not executed when running
883+
with `--doctest-modules`."""
884+
pytester.makepyfile(
885+
"""
886+
CONSTANT = 0
887+
888+
def setup_module():
889+
global CONSTANT
890+
CONSTANT = 1
891+
892+
def test():
893+
assert CONSTANT == 1
894+
"""
895+
)
896+
result = pytester.runpytest("--doctest-modules")
897+
assert result.ret == 0
898+
result.assert_outcomes(passed=1)
899+
881900

882901
class TestLiterals:
883902
@pytest.mark.parametrize("config_mode", ["ini", "comment"])

0 commit comments

Comments
 (0)