From b9cb87d862bb3f841d67723ac5717ce90b219dc2 Mon Sep 17 00:00:00 2001 From: Reagan Lee <96998476+reaganjlee@users.noreply.github.com> Date: Thu, 10 Aug 2023 17:43:01 -0700 Subject: [PATCH] simplify code / take out user-gen typeerror case --- src/_pytest/assertion/util.py | 8 ++------ testing/test_assertrewrite.py | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) 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