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
except Exception:
explanation = [
"(pytest_assertion plugin: representation of details failed. "
"Probably an object has a faulty __repr__.)",
str(_pytest._code.ExceptionInfo.from_current()),
"(pytest_assertion plugin: representation of details failed: {}.".format(
_pytest._code.ExceptionInfo.from_current()._getreprcrash()
),
" Probably an object has a faulty __repr__.)",
]
if not explanation:

View File

@ -677,8 +677,16 @@ class TestAssert_reprcompare:
expl = callequal([], [A()])
assert "ValueError" in "".join(expl)
expl = callequal({}, {"1": A()})
assert "faulty" in "".join(expl)
expl = callequal({}, {"1": A()}, verbose=2)
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):
"""