Skip to content

Commit

Permalink
[mypyc] Show traceback when emitfunc unit test fails (#17262)
Browse files Browse the repository at this point in the history
This makes debugging test failures easier.
  • Loading branch information
JukkaL committed May 18, 2024
1 parent dfab362 commit 12837ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion mypyc/test/test_emitfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 12837ea

Please sign in to comment.