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):
sshevlyagin
  • 1,310
  • 2
  • 16
  • 26
  • this is probably useful reading for you https://stackoverflow.com/questions/739654/how-to-make-a-chain-of-function-decorators/1594484#1594484 – Matthew Story Jul 01 '18 at 18:59

2 Answers2

25

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

sshevlyagin
  • 1,310
  • 2
  • 16
  • 26
  • 8
    Of course. Decorators are just a syntactic sugar. Just like `a(b(c()))` may not be the same as `c(b(a()))` – DeepSpace Jul 01 '18 at 18:37
0

I had the same error message for a similar use case. The error occured because I omitted to put mock as the first keyword argument in my testing function.

This works:

import unittest.mock as mock

@pytest.mark.parametrize('foo,bar', test_data)
@mock.patch('module.dog.Dog.__init__', return_value=None)
def test_update_activity_details_trainer_and_gear(_: mock.MagicMock, foo, bar):

This errors out with: In test_update_activity_details_trainer_and_gear: function uses no argument 'foo'

import unittest.mock as mock

@pytest.mark.parametrize('foo,bar', test_data)
@mock.patch('module.dog.Dog.__init__', return_value=None)
def test_update_activity_details_trainer_and_gear(foo, bar):
Alex Fortin
  • 2,105
  • 1
  • 18
  • 27