8000 gh-111881: Import doctest lazily in libregrtest by vstinner · Pull Request #111884 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111881: Import doctest lazily in libregrtest #111884

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 2 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Address Alex's review: keep match/case
  • Loading branch information
vstinner committed Nov 9, 2023
commit 0e9d0da97c168f0c8f6c8e79fbac58e12812942c
31 changes: 16 additions & 15 deletions Lib/test/libregrtest/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,23 @@ def regrtest_runner(result: TestResult, test_func, runtests: RunTests) -> None:

stats: TestStats | None

if isinstance(test_result, TestStats):
stats = test_result
elif isinstance(test_result, unittest.TestResult):
stats = TestStats.from_unittest(test_result)
elif test_result is None:
print_warning(f"{result.test_name} test runner returned None: {test_func}")
stats = None
else:
# Don't import doctest at top level since only few tests return
# a doctest.TestResult instance.
import doctest
if isinstance(test_result, doctest.TestResults):
stats = TestStats.from_doctest(test_result)
else:
print_warning(f"Unknown test result type: {type(test_result)}")
match test_result:
case TestStats():
stats = test_result
case unittest.TestResult():
stats = TestStats.from_unittest(test_result)
case None:
print_warning(f"{result.test_name} test runner returned None: {test_func}")
stats = None
case _:
# Don't import doctest at top level since only few tests return
# a doctest.TestResult instance.
import doctest
if isinstance(test_result, doctest.TestResults):
stats = TestStats.from_doctest(test_result)
else:
print_warning(f"Unknown test result type: {type(test_result)}")
stats = None

result.stats = stats

Expand Down
0