From 42c2c69da6244c6a6ab33239d3aa71275f3f0793 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 6 May 2024 15:41:49 +0100 Subject: [PATCH 1/2] [mypyc] Show traceback when emitfunc unit test fails This makes debugging easier. --- mypy/test/helpers.py | 6 ++++-- mypyc/test/test_emitfunc.py | 3 ++- 2 files changed, 6 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..c3843197c96c 100644 --- a/mypyc/test/test_emitfunc.py +++ b/mypyc/test/test_emitfunc.py @@ -841,7 +841,8 @@ 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: From 50505db8e3600c0aad6c102a2610f973eb0db437 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 May 2024 09:49:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/test/test_emitfunc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mypyc/test/test_emitfunc.py b/mypyc/test/test_emitfunc.py index c3843197c96c..317427afac5a 100644 --- a/mypyc/test/test_emitfunc.py +++ b/mypyc/test/test_emitfunc.py @@ -841,8 +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", - traceback=True) + assert_string_arrays_equal( + expected_lines, actual_lines, msg="Generated code unexpected", traceback=True + ) if skip_next: assert visitor.op_index == 1 else: