improve error msg and test

This commit is contained in:
Reagan Lee 2023-08-11 10:03:19 -07:00
parent ec1053cc16
commit c0cf822ca1
2 changed files with 7 additions and 4 deletions

View File

@ -136,7 +136,10 @@ def isiterable(obj: Any) -> bool:
return False
except Exception as e:
raise ValueError(
f"Unexpected exception {e!r} while testing object {obj!r}. Probably an issue with __iter__"
[
f"pytest_assertion plugin: unexpected exception {e!r} while testing object {obj!r}",
", probably from __iter__",
]
)
@ -203,9 +206,9 @@ def assertrepr_compare(
if (
isinstance(e, ValueError)
and (len(e.args) == 1)
and ("Unexpected exception" in str(e.args[0]))
and ("__iter__" in str(e.args[0]))
):
explanation = [e.args[0]]
explanation = e.args[0]
else:
explanation = [
"(pytest_assertion plugin: representation of details failed: {}.".format(

View File

@ -698,7 +698,7 @@ class TestAssertionRewrite:
msg = getmsg(f)
assert msg is not None
assert "Unexpected exception" in msg
assert "__iter__" in msg and "__repr__" not in msg
def test_formatchar(self) -> None:
def f() -> None: