Skip to content

Commit 156456b

Browse files
committed
More match/case
1 parent b083106 commit 156456b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

Lib/test/libregrtest/runtest.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,20 @@ def regrtest_runner(result, test_func, ns) -> None:
315315
if refleak:
316316
result.state = State.REFLEAK
317317

318-
if isinstance(test_result, TestStats):
319-
stats = test_result
320-
elif isinstance(test_result, unittest.TestResult):
321-
stats = TestStats.from_unittest(test_result)
322-
elif isinstance(test_result, doctest.TestResults):
323-
stats = TestStats.from_doctest(test_result)
324-
elif test_result is None:
325-
print_warning(f"{result.test_name} test runner returned None: {test_func}")
326-
stats = None
327-
else:
328-
print_warning(f"Unknown test result type: {type(test_result)}")
329-
stats = None
318+
match test_result:
319+
case TestStats():
320+
stats = test_result
321+
case unittest.TestResult():
322+
stats = TestStats.from_unittest(test_result)
323+
case doctest.TestResults():
324+
stats = TestStats.from_doctest(test_result)
325+
case None:
326+
print_warning(f"{result.test_name} test runner returned None: {test_func}")
327+
stats = None
328+
case _:
329+
print_warning(f"Unknown test result type: {type(test_result)}")
330+
stats = None
331+
330332
result.stats = stats
331333

332334

@@ -442,7 +444,7 @@ def _runtest_env_changed_exc(result: TestResult, ns: Namespace,
442444
result.state = State.PASSED
443445

444446

445-
def cleanup_test_droppings(test_name: str, verbose: int):
447+
def cleanup_test_droppings(test_name: str, verbose: int) -> None:
446448
# Try to clean up junk commonly left behind. While tests shouldn't leave
447449
# any files or directories behind, when a test fails that can be tedious
448450
# for it to arrange. The consequences can be especially nasty on Windows,

0 commit comments

Comments
 (0)