title: pytest monkeypatch methods with return values from parametrized method
body: <p>I'm working on writing some tests for a python app with the <code>pytest</code> framework. I have a problem in one of the tests, which I'm not sure the way it works.</p>
  
  <p>example:</p>
  
  <pre><code>@pytest.mark.parametrize("result, status, xml_err, xml_status",[
          ("PASS",True,False,"XML_ERROR"),
          ("Validation error", False, False, "XML_ERROR")
      ])
  def test_xml_build_neg(self, monkeypatch,result, status, xml_err, xml_status):
  
      def validate(self):
          return status, result, {}
  
      def transform(self, v_dict):
          return "&lt;xml/&gt;", 50.0, xml_status, xml_err
  
  
  
      monkeypatch.setattr(DataValidator, "validate", validate)
      monkeypatch.setattr(XMLTransformer, "transform", transform)
  
  
      o_result, o_status, o_xml_err, o_xml_status= XMLOutputBuilder().build(ExtractionResult(), "test", b"test")
  
      assert o_result == result, "Validation results not matching"
      assert o_status == status, "Validation Status not matching"
      .....
  </code></pre>
  
  <p>I did <code>monkeypatch</code> for some methods inside my <code>XMLOutputBuilder</code> to test some error scenarios. I expected my mock methods would return the values based on the incoming parameters, but it did not. I understand the behaviour is because the mocks and fixtures are loaded only once and it cannot be changed further (Correct me If I'm wrong).</p>
  
  <p>Is there any other methods to make this scenario work ? Or I have to write separate test methods for the parameters?</p>