Skip to content

Commit

Permalink
Revert change to traceback repr (#7535)
Browse files Browse the repository at this point in the history
* Revert change to traceback repr

* Add test and changelog entry

* Restore *exact* prev output

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
  • Loading branch information
Zac-HD and nicoddemus committed Jul 24, 2020
1 parent 7ec6401 commit 3a060b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/7534.bugfix.rst
@@ -0,0 +1 @@
Restored the previous formatting of ``TracebackEntry.__str__`` which was changed by accident.
10 changes: 9 additions & 1 deletion src/_pytest/_code/code.py
Expand Up @@ -262,7 +262,15 @@ def __str__(self) -> str:
raise
except BaseException:
line = "???"
return " File %r:%d in %s\n %s\n" % (self.path, self.lineno + 1, name, line)
# This output does not quite match Python's repr for traceback entries,
# but changing it to do so would break certain plugins. See
# https://github.com/pytest-dev/pytest/pull/7535/ for details.
return " File %r:%d in %s\n %s\n" % (
str(self.path),
self.lineno + 1,
name,
line,
)

@property
def name(self) -> str:
Expand Down
10 changes: 10 additions & 0 deletions testing/code/test_code.py
@@ -1,3 +1,4 @@
import re
import sys
from types import FrameType
from unittest import mock
Expand Down Expand Up @@ -170,6 +171,15 @@ def test_getsource(self) -> None:
assert len(source) == 6
assert "assert False" in source[5]

def test_tb_entry_str(self):
try:
assert False
except AssertionError:
exci = ExceptionInfo.from_current()
pattern = r" File '.*test_code.py':\d+ in test_tb_entry_str\n assert False"
entry = str(exci.traceback[0])
assert re.match(pattern, entry)


class TestReprFuncArgs:
def test_not_raise_exception_with_mixed_encoding(self, tw_mock) -> None:
Expand Down

0 comments on commit 3a060b7

Please sign in to comment.