Skip to content

Commit

Permalink
testing: add a regression test for setup_module + --doctest-modules
Browse files Browse the repository at this point in the history
Refs pytest-dev#12011 (only fails on 8.0.1, not main).
  • Loading branch information
bluetech authored and flying-sheep committed Apr 9, 2024
1 parent 7c08182 commit 985a54a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/12011.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a regression in 8.0.1 whereby ``setup_module`` xunit-style fixtures are not executed when ``--doctest-modules`` is passed.
19 changes: 19 additions & 0 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,25 @@ def test_foo():
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"])
Expand Down

0 comments on commit 985a54a

Please sign in to comment.