-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Show repr for callables used in an assert directly #11525
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
Comments
As fixtures are no longer callable, how about turning them into actual objects |
I think changing the |
Depends on what you mean by "actual objects". As long as they are still defined as functions, I'd be somewhat conservative about doing too much stuff with them. I don't know, but decorating a function turning that into something completely different from a function sounds kinda weird to me. Then again, maybe it's fine... |
Having fixtures as Definition objects that aren't callable instead of functions that fail might be a blessing when just wanting to search them |
With something like
(which is a common beginners mistake), pytest prints:
notably, without anything making it clear that
fixt
is a function, and not the value the user actually expected. Only when weprint(fixt)
it becomes clear that this is a function object and what the mistake was.This is due to:
pytest/src/_pytest/assertion/rewrite.py
Lines 459 to 461 in cdddd6d
which was originally introduced in 65edf87.
The rationale for it can be found in the related issue:
and it boils down to:
and
I believe this is useful in cases like
assert len(values) == 2
where we really don't need to drill down into whatlen
is. However, it hides vital information in the case that one side of the==
is a global callable directly, rather than it being used as a part of a bigger expression.The text was updated successfully, but these errors were encountered: