Skip to content

Commit 049eec8

Browse files
committed
Revert iter raises checks
This reverts commit e938580. Revert "improve error msg and test" This reverts commit c0cf822. Revert "error msg" This reverts commit ec1053c. Revert "changelog" This reverts commit d2dc8a7. Revert "simplify code / take out user-gen typeerror case" This reverts commit b9cb87d.
1 parent c0cf822 commit 049eec8

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

changelog/7966.bugfix.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/_pytest/assertion/util.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,6 @@ def isiterable(obj: Any) -> bool:
134134
return not istext(obj)
135135
except TypeError:
136136
return False
137-
except Exception as e:
138-
raise ValueError(
139-
[
140-
f"pytest_assertion plugin: unexpected exception {e!r} while testing object {obj!r}",
141-
", probably from __iter__",
142-
]
143-
)
144137

145138

146139
def has_default_eq(
@@ -202,20 +195,13 @@ def assertrepr_compare(
202195
explanation = _notin_text(left, right, verbose)
203196
except outcomes.Exit:
204197
raise
205-
except Exception as e:
206-
if (
207-
isinstance(e, ValueError)
208-
and (len(e.args) == 1)
209-
and ("__iter__" in str(e.args[0]))
210-
):
211-
explanation = e.args[0]
212-
else:
213-
explanation = [
214-
"(pytest_assertion plugin: representation of details failed: {}.".format(
215-
_pytest._code.ExceptionInfo.from_current()._getreprcrash()
216-
),
217-
" Probably an object has a faulty __repr__.)",
218-
]
198+
except Exception:
199+
explanation = [
200+
"(pytest_assertion plugin: representation of details failed: {}.".format(
201+
_pytest._code.ExceptionInfo.from_current()._getreprcrash()
202+
),
203+
" Probably an object has a faulty __repr__.)",
204+
]
219205

220206
if not explanation:
221207
return None

testing/test_assertrewrite.py

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

694694
def __eq__(self, o: object) -> bool:
695695
return self is o
@@ -698,7 +698,7 @@ def __eq__(self, o: object) -> bool:
698698

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

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

0 commit comments

Comments
 (0)