-
-
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
Failure when trying to call __repr__ because __iter__ is called? #7966
Comments
part of the assertion representation logic does try various things to tell more about the object the isiterable helper unfortunately calls it only checks for type-error, which doesn't account for broken implementations of iter |
we should decide whether we want to uphold the invariant that iter calls should only raise type errors, or whether we need to do something better in any case the error needs to be better |
Thanks, I actually did not think that there was some conventions about the type of exceptions being raised by special methods... I'm working on a custom interpreter for a different language, so I simply had a different |
CC @nicoddemus after reviewing i beleive we shoudl add 2 additional failure modes a) types that wrap data but dont proviede
i believe a better error should be triggered |
I agree with b), however I don't understand what you mean with a)... why use a multiline repr for types that don't have a |
@nicoddemus i have some helper pbjects around that just wrap around other sutff also openapi types dont necessarily iterate but have a nested multiline repr |
Hmm wait, I might be missing something, what do you mean by "multiline repr"? 🤔 |
@nicoddemus any type where repr is either multiline on its own or by using something some |
You mean calling |
Just use diff on it |
Hi, guys. When a test fails, Pytest fails to print ============================= test session starts ==============================
collecting ... collected 1 item
test_sample_users FAILED [100%]
sample_users = [<[KeyError('is_adult') raised in repr()] SampleUser object at 0x7fa9fad23a00>, <[KeyError('is_adult') raised in repr()] SampleUser object at 0x7fa9fad23be0>]
# the test traceback is not included, it does not matter My Versions: Python 3.10.1; pytest latest; pydantic master. QUESTION: Is it related to this issue, or I need to create a new one with more details? |
1. Problem
The following code
...will throw:
...because
__iter__
is called in order torepr()
the object?Is there a way to avoid
__iter__
being called when a test fails?2. Setup
Python 3.8.2 | pytest 6.1.1
The text was updated successfully, but these errors were encountered: