Skip to content

Commit 5e7b2ae

Browse files
committed
doctest: pytest_unconfigure: reset RUNNER_CLASS
This is important when used with ``pytester``'s ``runpytest_inprocess``. Since 07f20cc `pytest testing/acceptance_test.py -k test_doctest_id` would fail, since the second run would not consider the exception to be an instance of `doctest.DocTestFailure` anymore, since the module was re-imported, and use another failure message then in the short test summary info (and in the report itself): > FAILED test_doctest_id.txt::test_doctest_id.txt - doctest.DocTestFailure: <Do... while it should be: > FAILED test_doctest_id.txt::test_doctest_id.txt
1 parent 98fc937 commit 5e7b2ae

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

changelog/6039.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The ``PytestDoctestRunner`` is properly invalidated when unconfiguring the doctest plugin.
2+
3+
This is important when used with ``pytester``'s ``runpytest_inprocess``.

src/_pytest/doctest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ def pytest_addoption(parser):
8686
)
8787

8888

89+
def pytest_unconfigure():
90+
global RUNNER_CLASS
91+
92+
RUNNER_CLASS = None
93+
94+
8995
def pytest_collect_file(path, parent):
9096
config = parent.config
9197
if path.ext == ".py":

testing/acceptance_test.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,16 +859,21 @@ def test_doctest_id(self, testdir):
859859
4
860860
""",
861861
)
862-
result = testdir.runpytest("-rf")
863-
lines = result.stdout.str().splitlines()
864-
for line in lines:
865-
if line.startswith(("FAIL ", "FAILED ")):
866-
_fail, _sep, testid = line.partition(" ")
867-
break
868-
result = testdir.runpytest(testid, "-rf")
869-
result.stdout.fnmatch_lines(
870-
["FAILED test_doctest_id.txt::test_doctest_id.txt", "*1 failed*"]
871-
)
862+
testid = "test_doctest_id.txt::test_doctest_id.txt"
863+
expected_lines = [
864+
"*= FAILURES =*",
865+
"*_ ?doctest? test_doctest_id.txt _*",
866+
"FAILED test_doctest_id.txt::test_doctest_id.txt",
867+
"*= 1 failed in*",
868+
]
869+
result = testdir.runpytest(testid, "-rf", "--tb=short")
870+
result.stdout.fnmatch_lines(expected_lines)
871+
872+
# Ensure that re-running it will still handle it as
873+
# doctest.DocTestFailure, which was not the case before when
874+
# re-importing doctest, but not creating a new RUNNER_CLASS.
875+
result = testdir.runpytest(testid, "-rf", "--tb=short")
876+
result.stdout.fnmatch_lines(expected_lines)
872877

873878
def test_core_backward_compatibility(self):
874879
"""Test backward compatibility for get_plugin_manager function. See #787."""

0 commit comments

Comments
 (0)