sshevlyagin
sshevlyagin

Reputation: 1387

ValueError uses no argument in pytest, does order of decorators matter?

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):

Upvotes: 16

Views: 18225

Answers (2)

Alex Fortin
Alex Fortin

Reputation: 2415

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):

Upvotes: 0

sshevlyagin
sshevlyagin

Reputation: 1387

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

Upvotes: 27

Related Questions