How to using mock and parametrize on the same function

  pytest, pytest-mock, python, python-2.7

I’m trying to mock 3 functions in my code and parameterize the two other variables.

Here an example:

@pytest.mark.parametrize('a, b', [
    (5, 8),
])
@mock.patch('path_to_mocked_function3')
@mock.patch('path_to_mocked_function2')
@mock.patch('path_to_mocked_function1')
def test_function(self, mocked1, mocked2,
                            mocked3, a, b):
    mocked1.return_value = a
    mocked2.return_value = None
    mocked3.return_value = b
    output = export(**self.args).to_json()
    self.assertEqual(output, 5)

Now I want to parametrize a,b variables so I can run the code with few different test cases.

I’m getting this error:

TypeError: test_function() takes exactly 6 arguments (4 given)

Anyone knows why?

Source: Python Questions

LEAVE A COMMENT