Fix handle repr error with showlocals and verbose output

This commit is contained in:
Nikolay Kondratyev
2019-04-19 18:54:21 +03:00
parent e87d3d70e2
commit bc00d0f7db
6 changed files with 92 additions and 30 deletions

View File

@@ -134,6 +134,30 @@ class SessionTests(object):
!= -1
)
def test_broken_repr_with_showlocals_verbose(self, testdir):
p = testdir.makepyfile(
"""
class ObjWithErrorInRepr:
def __repr__(self):
raise NotImplementedError
def test_repr_error():
x = ObjWithErrorInRepr()
assert x == "value"
"""
)
reprec = testdir.inline_run("--showlocals", "-vv", p)
passed, skipped, failed = reprec.listoutcomes()
assert (len(passed), len(skipped), len(failed)) == (0, 0, 1)
entries = failed[0].longrepr.reprtraceback.reprentries
assert len(entries) == 1
repr_locals = entries[0].reprlocals
assert repr_locals.lines
assert len(repr_locals.lines) == 1
assert repr_locals.lines[0].startswith(
'x = <[NotImplementedError("") raised in repr()] ObjWithErrorInRepr'
)
def test_skip_file_by_conftest(self, testdir):
testdir.makepyfile(
conftest="""