assertrepr_compare: provide more info (location) with exceptions (#6728)
This commit is contained in:
parent
83137c89e9
commit
d89b5057ca
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue