-
-
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 cannot locate argument name when there is another decorator #6810
Comments
It works correctly if your decorator is well-behaved and uses functools.wraps: import functools
import pytest
def mydeco(foo):
@functools.wraps(foo)
def wrapped(*args, **kwargs):
print('wrapped!')
return foo(*args, **kwargs)
return wrapped
@pytest.mark.parametrize('x', [1, 2, 3])
@mydeco
def test_func(x):
assert x == 233 I don't think this is something pytest should work around. |
Thank you! It was really my problem not using decoration correctly... |
Thanks! I wonder if this is documented somewhere, or is |
its the documented standard way to keep the signature/metadata of a function |
Hmm, the Python documentation indeed doesn't say much about it. FWIW here's an article about it: https://lerner.co.il/2019/05/05/making-your-python-decorators-even-better-with-functool-wraps/ |
OK, thank you all for the input! |
This is a feature request.
Description
When
pytest.mark.parametrize
is combined with another decorator that takes(*args, **kwargs)
, it can't find the correct argument name, see examples below.Not working
Working
Why we need this?
@k-ye was trying to apply a test for all architectures using our
@ti.all_archs
decorator. It must be the last decorator to function so thatti.init()
could be called for each test.Then, we want to use
parametrize
and failed due to the reason shown above.Discussion: taichi-dev/taichi#527 (comment)
Possible solutions:
Thanks to @k-ye:
Related commits: https://github.com/taichi-dev/taichi/pull/527/files/11cb31b4fa1a2836ae015d5a463e4a0245b65346..2d6591825c6253bd2a01df8b3d4e2e71ed64c7a
The text was updated successfully, but these errors were encountered: