Skip to content
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

Order of decorators type: question #3646

Closed
sshevlyagin opened this issue Jul 1, 2018 · 5 comments
Closed

Order of decorators type: question #3646

sshevlyagin opened this issue Jul 1, 2018 · 5 comments
Labels
topic: marks related to marks, either the general marks or builtin topic: parametrize related to @pytest.mark.parametrize type: question general question, might be closed after 2 weeks of inactivity

Comments

@sshevlyagin
Copy link

  • pytest 3.6.2, python 3.6.1, OS X 10.3.15

I ran into a very cryptic error in pytest, after adding a '@pytest.mark.parametrize' decorator the test started throwing the following error:

ValueError: <function ... at ...> uses no argument 'parameters'

I found the source of the error here

Here's what the signature of my function looks like (simplified):

@patch('dog')
@pytest.mark.parametrize('foo,bar', test_data)
def test_update_activity_details_trainer_and_gear(self, foo, bar, dog):

Turns out the order of decorators in pytest matters

@pytest.mark.parametrize('foo,bar', test_data)
@patch('dog')
def test_update_activity_details_trainer_and_gear(self, dog, foo, bar):

Changing the order removed the error.

Question - could there be a more helpful error for n00bs like me?

Posted in stackoverflow as well

@pytestbot pytestbot added the topic: parametrize related to @pytest.mark.parametrize label Jul 1, 2018
@RonnyPfannschmidt
Copy link
Member

its not clear what to do there, imho mock,patch support should be deprecated as its unclean and doable much better these days (we shoul djust have a marker for patchings and be done with the funky mess the patch decorator introduces

@RonnyPfannschmidt RonnyPfannschmidt added type: question general question, might be closed after 2 weeks of inactivity topic: marks related to marks, either the general marks or builtin labels Jul 1, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #3581 (only decorator), #129 (Test functions with decorators are collected in wrong order), #2861 (Question re: order of execution of test fixtures), #3342 (Support for static typing), and #3601 ((question) Cleaning up from parameter generation).

@sshevlyagin
Copy link
Author

@RonnyPfannschmidt - thanks for the quick response, where should I look for how to do it better? Very curious to learn.

@RonnyPfannschmidt
Copy link
Member

pytest-mock is a starting point, but it currently has no marker replacing the patch decorator

@sshevlyagin
Copy link
Author

Appreciated, I'll check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: marks related to marks, either the general marks or builtin topic: parametrize related to @pytest.mark.parametrize type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants