Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f09f69

Browse filesBrowse files
authored
gh-111881: Import doctest lazily in libregrtest (#111884)
In most cases, doctest is not needed. So don't always import it at startup. The change reduces the number of modules already imported when a test is run.
1 parent 2f2a0a3 commit 6f09f69
Copy full SHA for 6f09f69

File tree

Expand file treeCollapse file tree

1 file changed

+8
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-5
lines changed

‎Lib/test/libregrtest/single.py

Copy file name to clipboardExpand all lines: Lib/test/libregrtest/single.py
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import doctest
21
import faulthandler
32
import gc
43
import importlib
@@ -99,14 +98,18 @@ def regrtest_runner(result: TestResult, test_func, runtests: RunTests) -> None:
9998
stats = test_result
10099
case unittest.TestResult():
101100
stats = TestStats.from_unittest(test_result)
102-
case doctest.TestResults():
103-
stats = TestStats.from_doctest(test_result)
104101
case None:
105102
print_warning(f"{result.test_name} test runner returned None: {test_func}")
106103
stats = None
107104
case _:
108-
print_warning(f"Unknown test result type: {type(test_result)}")
109-
stats = None
105+
# Don't import doctest at top level since only few tests return
106+
# a doctest.TestResult instance.
107+
import doctest
108+
if isinstance(test_result, doctest.TestResults):
109+
stats = TestStats.from_doctest(test_result)
110+
else:
111+
print_warning(f"Unknown test result type: {type(test_result)}")
112+
stats = None
110113

111114
result.stats = stats
112115

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.