From c0cf822ca1d5d6ac74f46ddccbe377c254c6084a Mon Sep 17 00:00:00 2001 From: Reagan Lee <96998476+reaganjlee@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:03:19 -0700 Subject: [PATCH] improve error msg and test --- src/_pytest/assertion/util.py | 9 ++++++--- testing/test_assertrewrite.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 613a40b97..d20c2363e 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -136,7 +136,10 @@ def isiterable(obj: Any) -> bool: return False except Exception as e: raise ValueError( - f"Unexpected exception {e!r} while testing object {obj!r}. Probably an issue with __iter__" + [ + f"pytest_assertion plugin: unexpected exception {e!r} while testing object {obj!r}", + ", probably from __iter__", + ] ) @@ -203,9 +206,9 @@ def assertrepr_compare( if ( isinstance(e, ValueError) and (len(e.args) == 1) - and ("Unexpected exception" in str(e.args[0])) + and ("__iter__" in str(e.args[0])) ): - explanation = [e.args[0]] + explanation = e.args[0] else: explanation = [ "(pytest_assertion plugin: representation of details failed: {}.".format( diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index b4e3e5d53..62c6bb8d4 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -698,7 +698,7 @@ class TestAssertionRewrite: msg = getmsg(f) assert msg is not None - assert "Unexpected exception" in msg + assert "__iter__" in msg and "__repr__" not in msg def test_formatchar(self) -> None: def f() -> None: