-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
pytest.mark.parametrize fails with lambdas #1111
Comments
pytest.mark.parametrize
fails with lambdas
Thanks for the report @mithrandi! 😄 |
this looks like a lambda is mistaken for a positional arggument |
Now the code above produces the following output:
And it is not failure anymore. Tested with latest pytest version from repository on Python 2.7.12 & 3.5.1. |
@mithrandi can thos one be closed based on the changes in master |
@RonnyPfannschmidt If something still fails but in a different way, I don't think it should be closed 😉 |
@The-Compiler as far as i can tell however we now have a normal report of the object there and the markdecorator invocation does consider a lambda an argument, not afunction that should be decorated so i think with the change in reporting, everything works as designed |
I don't think we should support defining test functions using lambdas at all, I at least can't think of a valid use case for it. So I agree with @RonnyPfannschmidt that the error message is now appropriate, which I think was the heart of this issue. @mithrandi what do you think? |
The use case is that you are decorating a test function with from functools import wraps
def enhance(f):
return wraps(f)(lambda *a, **kw: f(enhancement, *a, **kw)) |
hmm, interesting, can you perhaps link to the library in question? |
Unfortunately the exact circumstances where this came up are lost to me in the mists of time; I vaguely recall I was investigating something to do with https://github.com/HypothesisWorks/hypothesis-python but nothing beyond that. |
i see, i propose closing then |
I can imagine there are other libaries doing this kind of thing. I'm going to be honest: I think pytest should support it, and it might be quite easy, but I'm not volunteering to do it - too much on my plate right now, sorry. |
In light of that, I agree with @The-Compiler that we should at least try to support it, if it's easy. What do you think @RonnyPfannschmidt? If so, I propose closing this one and opening another issue, like "Allow lambdas to be used as test functions" or so. |
Nope, if the function name is Handling those different in marks means we are certain to break testsuites for bad reason |
I'm not sure that's the case here, at least with the example given by @mithrandi:
Note that the name of the decorated function is Is there anything special about lambdas that would prevent them from being collected as tests? I didn't take a look at the code, just wondering. |
@nicoddemus the code in the marker specifically triggers for lambdas and ignores only them without checking into a wrapped function |
Oh I see, it complicates the marker code, not the collection code. Got it. |
Since we aren't sure if we should do this at all (I still think we should if possible...), this definitely shouldn't block 3.0. |
closing as it seems we cant reproduce, please reopen if a reproducer happens to get known |
For example, the following:
fails like this:
This reproducer may seem rather odd by itself, but something like this may arise with a decorator that returns a lambda.
I have confirmed this failure on pytest 2.7.0, 2.7.3, 2.8.0, and 2.8.1.
The text was updated successfully, but these errors were encountered: