Skip to content

Commit c0cf822

Browse files
committed
improve error msg and test
1 parent ec1053c commit c0cf822

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/_pytest/assertion/util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def isiterable(obj: Any) -> bool:
136136
return False
137137
except Exception as e:
138138
raise ValueError(
139-
f"Unexpected exception {e!r} while testing object {obj!r}. Probably an issue with __iter__"
139+
[
140+
f"pytest_assertion plugin: unexpected exception {e!r} while testing object {obj!r}",
141+
", probably from __iter__",
142+
]
140143
)
141144

142145

@@ -203,9 +206,9 @@ def assertrepr_compare(
203206
if (
204207
isinstance(e, ValueError)
205208
and (len(e.args) == 1)
206-
and ("Unexpected exception" in str(e.args[0]))
209+
and ("__iter__" in str(e.args[0]))
207210
):
208-
explanation = [e.args[0]]
211+
explanation = e.args[0]
209212
else:
210213
explanation = [
211214
"(pytest_assertion plugin: representation of details failed: {}.".format(

testing/test_assertrewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def __eq__(self, o: object) -> bool:
698698

699699
msg = getmsg(f)
700700
assert msg is not None
701-
assert "Unexpected exception" in msg
701+
assert "__iter__" in msg and "__repr__" not in msg
702702

703703
def test_formatchar(self) -> None:
704704
def f() -> None:

0 commit comments

Comments
 (0)