Skip to content

Commit 85b0504

Browse files
committed
Version guard unit test
1 parent 3661ee3 commit 85b0504

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

testing/code/test_excinfo.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ def entry():
849849
assert basename in str(reprtb.reprfileloc.path)
850850
assert reprtb.reprfileloc.lineno == 3
851851

852+
@pytest.mark.skipif(
853+
"sys.version_info < (3,11)",
854+
reason="Column level traceback info added in python 3.11",
855+
)
852856
def test_repr_traceback_entry_short_carets(self, importasmod) -> None:
853857
mod = importasmod(
854858
"""
@@ -1397,13 +1401,22 @@ def h():
13971401
assert tw_mock.lines[40] == ("_ ", None)
13981402
assert tw_mock.lines[41] == ""
13991403
assert tw_mock.lines[42] == " def h():"
1400-
assert tw_mock.lines[43] == "> if True: raise AttributeError()"
1401-
assert tw_mock.lines[44] == " ^^^^^^^^^^^^^^^^^^^^^^"
1402-
assert tw_mock.lines[45] == "E AttributeError"
1403-
assert tw_mock.lines[46] == ""
1404-
line = tw_mock.get_write_msg(47)
1405-
assert line.endswith("mod.py")
1406-
assert tw_mock.lines[48] == ":15: AttributeError"
1404+
# On python 3.11 and greater, check for carets in the traceback.
1405+
if sys.version_info >= (3, 11):
1406+
assert tw_mock.lines[43] == "> if True: raise AttributeError()"
1407+
assert tw_mock.lines[44] == " ^^^^^^^^^^^^^^^^^^^^^^"
1408+
assert tw_mock.lines[45] == "E AttributeError"
1409+
assert tw_mock.lines[46] == ""
1410+
line = tw_mock.get_write_msg(47)
1411+
assert line.endswith("mod.py")
1412+
assert tw_mock.lines[48] == ":15: AttributeError"
1413+
else:
1414+
assert tw_mock.lines[43] == "> raise AttributeError()"
1415+
assert tw_mock.lines[44] == "E AttributeError"
1416+
assert tw_mock.lines[45] == ""
1417+
line = tw_mock.get_write_msg(46)
1418+
assert line.endswith("mod.py")
1419+
assert tw_mock.lines[47] == ":15: AttributeError"
14071420

14081421
@pytest.mark.parametrize("mode", ["from_none", "explicit_suppress"])
14091422
def test_exc_repr_chain_suppression(self, importasmod, mode, tw_mock):

0 commit comments

Comments
 (0)