assertrepr_compare: provide more info (location) with exceptions (#6728)

This commit is contained in:
Daniel Hahler 2020-02-14 02:17:05 +01:00 committed by GitHub
parent 83137c89e9
commit d89b5057ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -175,9 +175,10 @@ def assertrepr_compare(config, op: str, left: Any, right: Any) -> Optional[List[
raise raise
except Exception: except Exception:
explanation = [ explanation = [
"(pytest_assertion plugin: representation of details failed. " "(pytest_assertion plugin: representation of details failed: {}.".format(
"Probably an object has a faulty __repr__.)", _pytest._code.ExceptionInfo.from_current()._getreprcrash()
str(_pytest._code.ExceptionInfo.from_current()), ),
" Probably an object has a faulty __repr__.)",
] ]
if not explanation: if not explanation:

View File

@ -677,8 +677,16 @@ class TestAssert_reprcompare:
expl = callequal([], [A()]) expl = callequal([], [A()])
assert "ValueError" in "".join(expl) assert "ValueError" in "".join(expl)
expl = callequal({}, {"1": A()}) expl = callequal({}, {"1": A()}, verbose=2)
assert "faulty" in "".join(expl) assert expl[0].startswith("{} == <[ValueError")
assert "raised in repr" in expl[0]
assert expl[1:] == [
"(pytest_assertion plugin: representation of details failed:"
" {}:{}: ValueError: 42.".format(
__file__, A.__repr__.__code__.co_firstlineno + 1
),
" Probably an object has a faulty __repr__.)",
]
def test_one_repr_empty(self): def test_one_repr_empty(self):
""" """