3

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?

Shahriar
  • 1,855
  • 2
  • 21
  • 45
  • 2
    Your code looks good so far, assuming it is in a class (otherwise the `self` parameter makes no sense). Can you provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – MrBean Bremen Jul 18 '21 at 06:47
  • I'm using the self because In the set-up I'm setting the args for the function – Dor Ben zvi Jul 18 '21 at 06:49
  • Ok, your test class does not derive from `unittest.TestCase`, right? Because that wouldn't work with `pytest.parametrize`. – MrBean Bremen Jul 18 '21 at 07:51
  • My test class derives from unitttest.TestCase, so I cant use pytest.parametrize? – Dor Ben zvi Jul 18 '21 at 08:02
  • 1
    Right. `unittest` does not know about `pytest`, so it can't handle it. Is there a reason you derive from `unittest.TestCase`, if you are using `pytest` anyway? – MrBean Bremen Jul 18 '21 at 08:11
  • @MrBeanBreme Thanks, you know what it the right way if I want to use a class? – Dor Ben zvi Jul 18 '21 at 08:17
  • 1
    Just don't derive from `unittest.TestCase`, e.g. don't derive from anything (or from `object`, if you are still in Python 2). – MrBean Bremen Jul 18 '21 at 08:21

0 Answers0