-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve reporting from __iter__ exceptions #11308
Conversation
1ae5e73
to
c0cf822
Compare
src/_pytest/assertion/util.py
Outdated
except TypeError: | ||
return False | ||
except Exception as e: | ||
raise ValueError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should probably just replace except TypeError:
with except Exception:
here - if calling iter(obj)
raises an error, it seems reasonable to treat that as "not iterable" rather than a special error case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I think the error message is helpful if people don't expect it, but I can see that this adds to things to maintain
Thanks Reagan! |
Fixes #7966
Previously, the assertion rewrite mechanism would fail to capture raised errors within
__iter__
and suggest the error is within__repr__
, which this new reporting now fixes.