From 12837eaedcab5352dd2e3df925b21373597762e8 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Sat, 18 May 2024 13:31:36 +0100 Subject: [PATCH] [mypyc] Show traceback when emitfunc unit test fails (#17262) This makes debugging test failures easier. --- mypy/test/helpers.py | 6 ++++-- mypyc/test/test_emitfunc.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mypy/test/helpers.py b/mypy/test/helpers.py index 50de50e60004..f26c3b042e8c 100644 --- a/mypy/test/helpers.py +++ b/mypy/test/helpers.py @@ -104,7 +104,9 @@ def render_diff_range( output.write("\n") -def assert_string_arrays_equal(expected: list[str], actual: list[str], msg: str) -> None: +def assert_string_arrays_equal( + expected: list[str], actual: list[str], msg: str, *, traceback: bool = False +) -> None: """Assert that two string arrays are equal. Display any differences in a human-readable form. @@ -136,7 +138,7 @@ def assert_string_arrays_equal(expected: list[str], actual: list[str], msg: str) "Update the test output using --update-data -n0 " "(you can additionally use the -k selector to update only specific tests)\n" ) - pytest.fail(msg, pytrace=False) + pytest.fail(msg, pytrace=traceback) def assert_module_equivalence(name: str, expected: Iterable[str], actual: Iterable[str]) -> None: diff --git a/mypyc/test/test_emitfunc.py b/mypyc/test/test_emitfunc.py index b16387aa40af..317427afac5a 100644 --- a/mypyc/test/test_emitfunc.py +++ b/mypyc/test/test_emitfunc.py @@ -841,7 +841,9 @@ def assert_emit( else: expected_lines = expected.rstrip().split("\n") expected_lines = [line.strip(" ") for line in expected_lines] - assert_string_arrays_equal(expected_lines, actual_lines, msg="Generated code unexpected") + assert_string_arrays_equal( + expected_lines, actual_lines, msg="Generated code unexpected", traceback=True + ) if skip_next: assert visitor.op_index == 1 else: