Skip to content

Commit 61133ba

Browse files
committed
un-iterable fix
1 parent 049eec8 commit 61133ba

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

changelog/7966.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removes unhelpful error message from assertion rewrite mechanism when exceptions raised in __iter__ methods, and instead treats them as un-iterable.

src/_pytest/assertion/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def isiterable(obj: Any) -> bool:
132132
try:
133133
iter(obj)
134134
return not istext(obj)
135-
except TypeError:
135+
except Exception:
136136
return False
137137

138138

testing/test_assertrewrite.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,16 +689,19 @@ def test_assert_handling_raise_in__iter__(self) -> None:
689689
def f() -> None:
690690
class A:
691691
def __iter__(self):
692-
raise TypeError("user message")
692+
raise ValueError()
693693

694694
def __eq__(self, o: object) -> bool:
695695
return self is o
696696

697+
def __repr__(self):
698+
return "<A object>"
699+
697700
assert A() == A()
698701

699702
msg = getmsg(f)
700703
assert msg is not None
701-
assert "Unexpected exception" in msg
704+
assert "<A object> == <A object>" in msg
702705

703706
def test_formatchar(self) -> None:
704707
def f() -> None:

0 commit comments

Comments
 (0)