vendredi 30 janvier 2015

Python Mock patch.multiple argument names

It's possible to change the test argument name of a patched class or function when using patch as a decorator.



@patch('module.ClassName2')
@patch('module.ClassName1')
def test(MockClass1, MockClass2):
MockClass1.test.return_value = 'testing'


However, I can't seem to find in the documentation how to differentiate the original object and the mock when using patch.multiple.



@patch.multiple('module.ClassName', foo=DEFAULT, bar=DEFAULT)
def test(foo, bar):
foo.return_value = 'foo'


In the above example, the arguments in the test must be foo and bar. Is there any clean way to allow their use with a clearer differentiation, e.g. mock_foo?


This would also be handy in cases where the original class or method is needed in part of the test, avoiding imports like from module import Class as OriginalClass


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire