Skip to content

Commit 6d2f432

Browse files
committed
Personal review fixes
1 parent 24e7820 commit 6d2f432

4 files changed

Lines changed: 33 additions & 44 deletions

File tree

‎Lib/test/libregrtest/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def create_run_tests(self, tests: TestTuple) -> RunTests:
525525
hunt_refleak=self.hunt_refleak,
526526
test_dir=self.test_dir,
527527
use_junit=(self.junit_filename is not None),
528-
final_run=not (self.want_rerun and not self.python_cmd),
528+
final_run=not self.want_rerun or bool(self.python_cmd),
529529
coverage=self.coverage,
530530
memory_limit=self.memory_limit,
531531
gc_threshold=self.gc_threshold,

‎Lib/test/libregrtest/reporter.py‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .findtests import findtestdir
99
from .result import TestResult
10-
lazy from .results import TestResults
10+
from .results import TestResults
1111
from .runtests import RunTests
1212
from .utils import count
1313

@@ -31,20 +31,20 @@ def summary(self, results: TestResults, state: str) -> None:
3131
@staticmethod
3232
def parse_traceback(traceback: str) -> tuple[str | None, str | None, str]:
3333
"""Return (filename, line, exception) of a failure."""
34-
frames = re.findall(r'^ *File "(.*)", line (\d+)', traceback,
35-
re.MULTILINE)
36-
test_frames = [frame for frame in frames
37-
if pathlib.Path(frame[0]).name.startswith('test_')]
34+
# A frame is its "File" line and its source lines
35+
frames = list(re.finditer(
36+
r'^ *File "(.*)", line (\d+).*\n(?: .*\n)*', traceback,
37+
re.MULTILINE))
38+
filename = line = None
39+
exception = traceback
40+
if frames:
41+
filename, line = frames[0].groups()
42+
exception = traceback[frames[-1].end():]
3843
# Prefer the last frame in a test file, the assertion
39-
if test_frames:
40-
filename, line = test_frames[-1]
41-
elif frames:
42-
filename, line = frames[0]
43-
else:
44-
filename = line = None
45-
exception = re.split(r'^ File .*\n(?: .*\n)*', traceback,
46-
flags=re.MULTILINE)[-1].strip()
47-
return filename, line, exception
44+
for frame in frames:
45+
if pathlib.Path(frame[1]).name.startswith("test_"):
46+
filename, line = frame.groups()
47+
return filename, line, exception.strip()
4848

4949

5050
def get_reporter() -> Reporter:
@@ -93,7 +93,8 @@ def test_result(self, result: TestResult) -> None:
9393
self.annotate(result.test_name, decolor(message), filename)
9494

9595
def annotate(self, title: str, message: str, filename: str | None,
96-
line: str | None = None, stream: TextIO | None = None) -> None:
96+
line: str | None = None,
97+
stream: TextIO | None = None) -> None:
9798
if filename:
9899
# Make installed stdlib paths relative to the checkout
99100
path = pathlib.Path(filename)
@@ -120,8 +121,8 @@ def summary(self, results: TestResults, state: str) -> None:
120121
for result in failed:
121122
blocks.append(f"### {decolor(str(result))}")
122123
if result.env_changed_reasons:
123-
blocks.append("\n".join(f"- {reason}"
124-
for reason in result.env_changed_reasons))
124+
blocks.append("\n".join(
125+
f"- {reason}" for reason in result.env_changed_reasons))
125126
for name, traceback in result.failed_test_cases:
126127
# Expand short tracebacks if there are only a few
127128
if ncases <= 5 and traceback.count("\n") < 30:

‎Lib/test/libregrtest/setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .filter import set_match_tests
1414
from .reporter import get_reporter
1515
from .runtests import RunTests
16-
lazy from .testresult import RegressionTestResult
16+
from .testresult import RegressionTestResult
1717
from .utils import (
1818
setup_unraisable_hook, setup_threading_excepthook,
1919
adjust_rlimit_nofile)

‎Lib/test/test_regrtest.py‎

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,35 +1657,23 @@ def test_fail(self):
16571657
fail = self.create_test('reporter_fail', code)
16581658
crash = self.create_test('reporter_crash',
16591659
code.replace('self.fail()', 'os._exit(1)'))
1660-
fail_case = (os.path.join(self.tmptestdir, f'{fail}.py'), '6',
1661-
f'test_fail ({fail}.Tests.test_fail)')
1662-
filename = os.path.join(self.tmptestdir, 'github_step_summary.md')
1663-
env = dict(os.environ, GITHUB_STEP_SUMMARY=filename)
1660+
summary = os.path.join(self.tmptestdir, 'summary.md')
1661+
env = dict(os.environ, GITHUB_STEP_SUMMARY=summary)
16641662

1665-
def reported(output):
1666-
return re.findall(r'^::error file=(.*),line=(\d+),title=(.*)::',
1667-
output, re.MULTILINE)
1663+
def reported(*args, exitcode=EXITCODE_BAD_TEST):
1664+
output = self.run_tests('-j1', *args, env=env, exitcode=exitcode)
1665+
return re.findall(r'^::error file=.*,title=(\w+)', output,
1666+
re.MULTILINE)
16681667

1668+
self.assertEqual(reported(self.create_test(), exitcode=0), [])
1669+
self.assertFalse(os.path.exists(summary))
1670+
# Quiet mode doesn't print the failure, but reports it
1671+
self.assertEqual(reported(fail), ['test_fail'])
16691672
# Only the re-run is reported
1670-
output = self.run_tests('-j1', '--rerun', fail, crash,
1671-
env=env, exitcode=EXITCODE_BAD_TEST)
1672-
self.assertEqual(reported(output), [
1673-
fail_case,
1674-
(os.path.join(self.tmptestdir, f'{crash}.py'), '1', crash),
1675-
], output)
1676-
with open(filename, encoding='utf-8') as fp:
1673+
self.assertEqual(reported('--rerun', fail, crash),
1674+
['test_fail', crash])
1675+
with open(summary, encoding='utf-8') as fp:
16771676
self.assertIn('2 test files and 1 test case failed', fp.read())
1678-
os_helper.unlink(filename)
1679-
1680-
# Quiet mode doesn't print the failure, but reports it
1681-
output = self.run_tests('-j1', fail, env=env,
1682-
exitcode=EXITCODE_BAD_TEST)
1683-
self.assertEqual(reported(output), [fail_case], output)
1684-
os_helper.unlink(filename)
1685-
1686-
output = self.run_tests(self.create_test(), env=env)
1687-
self.assertEqual(reported(output), [])
1688-
self.assertFalse(os.path.exists(filename))
16891677

16901678
def test_rerun_fail(self):
16911679
# FAILURE then FAILURE

0 commit comments

Comments
 (0)