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
|
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:
|
||||||
|
|
|
@ -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):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue