Skip to content

Commit 11c2c6d

Browse files
authored
Fix test-data diffs not to produce traceback (#14549)
If the cause for failure is a diff, the traceback isn't helpful and in fact we've been trying to suppress it with `__tracebackhide__` already.
1 parent 5c459d2 commit 11c2c6d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mypy/test/data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,14 @@ def reportinfo(self) -> tuple[str, int, str]:
359359
return self.file, self.line, self.name
360360

361361
def repr_failure(self, excinfo: Any, style: Any | None = None) -> str:
362-
if excinfo.errisinstance(SystemExit):
362+
if isinstance(excinfo.value, SystemExit):
363363
# We assume that before doing exit() (which raises SystemExit) we've printed
364364
# enough context about what happened so that a stack trace is not useful.
365365
# In particular, uncaught exceptions during semantic analysis or type checking
366366
# call exit() and they already print out a stack trace.
367367
excrepr = excinfo.exconly()
368+
elif isinstance(excinfo.value, pytest.fail.Exception) and not excinfo.value.pytrace:
369+
excrepr = excinfo.exconly()
368370
else:
369371
self.parent._prunetraceback(excinfo)
370372
excrepr = excinfo.getrepr(style="short")

mypy/test/helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def assert_string_arrays_equal(expected: list[str], actual: list[str], msg: str)
5151
5252
Display any differences in a human-readable form.
5353
"""
54-
__tracebackhide__ = True
55-
5654
actual = clean_up(actual)
5755
actual = [line.replace("can't", "cannot") for line in actual]
5856
expected = [line.replace("can't", "cannot") for line in expected]
@@ -117,7 +115,7 @@ def assert_string_arrays_equal(expected: list[str], actual: list[str], msg: str)
117115
# long lines.
118116
show_align_message(expected[first_diff], actual[first_diff])
119117

120-
raise AssertionError(msg)
118+
pytest.fail(msg, pytrace=False)
121119

122120

123121
def assert_module_equivalence(name: str, expected: Iterable[str], actual: Iterable[str]) -> None:

0 commit comments

Comments
 (0)