Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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