Skip to content

Commit 29102cb

Browse files
committed
Fix repr cycle test
1 parent 85b0504 commit 29102cb

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

testing/code/test_excinfo.py

+39-19
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ def h():
14111411
assert line.endswith("mod.py")
14121412
assert tw_mock.lines[48] == ":15: AttributeError"
14131413
else:
1414-
assert tw_mock.lines[43] == "> raise AttributeError()"
1414+
assert tw_mock.lines[43] == "> if True: raise AttributeError()"
14151415
assert tw_mock.lines[44] == "E AttributeError"
14161416
assert tw_mock.lines[45] == ""
14171417
line = tw_mock.get_write_msg(46)
@@ -1535,24 +1535,44 @@ def unreraise():
15351535
r = excinfo.getrepr(style="short")
15361536
r.toterminal(tw_mock)
15371537
out = "\n".join(line for line in tw_mock.lines if isinstance(line, str))
1538-
expected_out = textwrap.dedent(
1539-
"""\
1540-
:13: in unreraise
1541-
reraise()
1542-
:10: in reraise
1543-
raise Err() from e
1544-
E test_exc_chain_repr_cycle0.mod.Err
1545-
1546-
During handling of the above exception, another exception occurred:
1547-
:15: in unreraise
1548-
raise e.__cause__
1549-
:8: in reraise
1550-
fail()
1551-
:5: in fail
1552-
return 0 / 0
1553-
^^^^^
1554-
E ZeroDivisionError: division by zero"""
1555-
)
1538+
# Assert highlighting carets in python3.11+
1539+
if sys.version_info >= (3, 11):
1540+
expected_out = textwrap.dedent(
1541+
"""\
1542+
:13: in unreraise
1543+
reraise()
1544+
:10: in reraise
1545+
raise Err() from e
1546+
E test_exc_chain_repr_cycle0.mod.Err
1547+
1548+
During handling of the above exception, another exception occurred:
1549+
:15: in unreraise
1550+
raise e.__cause__
1551+
:8: in reraise
1552+
fail()
1553+
:5: in fail
1554+
return 0 / 0
1555+
^^^^^
1556+
E ZeroDivisionError: division by zero"""
1557+
)
1558+
else:
1559+
expected_out = textwrap.dedent(
1560+
"""\
1561+
:13: in unreraise
1562+
reraise()
1563+
:10: in reraise
1564+
raise Err() from e
1565+
E test_exc_chain_repr_cycle0.mod.Err
1566+
1567+
During handling of the above exception, another exception occurred:
1568+
:15: in unreraise
1569+
raise e.__cause__
1570+
:8: in reraise
1571+
fail()
1572+
:5: in fail
1573+
return 0 / 0
1574+
E ZeroDivisionError: division by zero"""
1575+
)
15561576
assert out == expected_out
15571577

15581578
def test_exec_type_error_filter(self, importasmod):

0 commit comments

Comments
 (0)