Skip to content

Commit

Permalink
python 3.11 fixes: traceback ^^^ helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jan 23, 2022
1 parent 9b3f2a3 commit 2ab3aba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import sys
import textwrap
from pathlib import Path
from typing import Callable
Expand Down Expand Up @@ -200,6 +201,7 @@ def test_doctest_unexpected_exception(self, pytester: Pytester):
"Traceback (most recent call last):",
' File "*/doctest.py", line *, in __run',
" *",
*((" *^^^^*",) if sys.version_info >= (3, 11) else ()),
' File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>',
"ZeroDivisionError: division by zero",
"*/test_doctest_unexpected_exception.txt:2: UnexpectedException",
Expand Down
21 changes: 19 additions & 2 deletions testing/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import os
import re
import sys
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -44,16 +45,32 @@ def pytest_internalerror(excrepr, excinfo):
assert result.ret == ExitCode.INTERNAL_ERROR
assert result.stdout.lines[0] == "INTERNALERROR> Traceback (most recent call last):"

end_lines = (
result.stdout.lines[-4:]
if sys.version_info >= (3, 11)
else result.stdout.lines[-3:]
)

if exc == SystemExit:
assert result.stdout.lines[-3:] == [
assert end_lines == [
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
'INTERNALERROR> raise SystemExit("boom")',
*(
("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
if sys.version_info >= (3, 11)
else ()
),
"INTERNALERROR> SystemExit: boom",
]
else:
assert result.stdout.lines[-3:] == [
assert end_lines == [
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
'INTERNALERROR> raise ValueError("boom")',
*(
("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
if sys.version_info >= (3, 11)
else ()
),
"INTERNALERROR> ValueError: boom",
]
if returncode is False:
Expand Down

0 comments on commit 2ab3aba

Please sign in to comment.