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
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
GitMate.io thinks possibly related issues are https://github.com/pytest-dev/pytest/issues/3581 (only decorator), https://github.com/pytest-dev/pytest/issues/129 (Test functions with decorators are collected in wrong order), https://github.com/pytest-dev/pytest/issues/2861 (Question re: order of execution of test fixtures), https://github.com/pytest-dev/pytest/issues/3342 (Support for static typing), and https://github.com/pytest-dev/pytest/issues/3601 ((question) Cleaning up from parameter generation).
@RonnyPfannschmidt - thanks for the quick response, where should I look for how to do it better? Very curious to learn.
pytest-mock is a starting point, but it currently has no marker replacing the patch decorator
Appreciated, I'll check it out.
Most helpful comment
pytest-mock is a starting point, but it currently has no marker replacing the patch decorator