diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 47244b688..22eec1809 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -132,13 +132,9 @@ def isiterable(obj: Any) -> bool: try: iter(obj) return not istext(obj) + except TypeError: + return False except Exception as e: - if ( - isinstance(e, TypeError) - and (len(e.args) == 1) - and "iter() returned non-iterator of type" in str(e.args[0]) - ): - return False raise ValueError(f"Unexpected exception {e!r} while testing object {obj!r}") diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index d85c8bed6..b4e3e5d53 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -689,7 +689,7 @@ class TestAssertionRewrite: def f() -> None: class A: def __iter__(self): - raise TypeError("user message") + raise ValueError() def __eq__(self, o: object) -> bool: return self is o