title: How to unit test using patch with a side effect with Pytest parametrize?
body: <p>I'm trying to test my function that takes in 3 arguments and also contains another function which I'm trying to mock. The issue is that the mock does not cycle through the side effect; I can't 'match' the first set of values I want to test (the first parametrized arguments) with the first value in the side effect; the second set of parametrized arguments with the second value in the side effect and so forth.</p>
  
  <p>I tried to use fixtures and played around with parametrize but to no avail. </p>
  
  <h1>TEST CODE</h1>
  
  <pre><code># I go through each set of values I want to test with a different expected output
  @pytest.mark.parametrize('banner, year, month, expected', [
      ('ctr', 2019, 1, r'A\path\file.csv'),
      ('mks', 2019, 1, r'B\path\file.csv'),
      ('sc', 2019, 1, r'C\path\file.csv'),
      ('atm', 2019, 1, r'D\path\file.csv')
  ])
  @mock.patch('import.path.to.function.path_formatting')
  def test_files(mock_directory_path_banner, banner, year, month, expected):
      # the mocked function always returns 'ctr'
      mock_directory_path_banner.side_effect = ['ctr', 'mww', 'fgl', 'fgl']
      result = get_loyalty_sales_files(banner, year, month)
      assert expected == result
  </code></pre>
  
  <p>In total, there are four tests. The first passes as the parameterized test uses the correct value from the mock (ctr). However the remaining tests all fail because a new mock is not called for each parameterized test. I expect that a new mock is called each time a new parameterized set of values is cycled through, but that's not the case.</p>