dimanche 30 octobre 2016

Making a wrapper for `mock.patch`

Some customized patches from mock.patch I want to use over and over without littering my test code with copy-pastes of the patch setup. e.g. this very handy patch of datetime.date, which would fill my code with

with patch('mymodule.date') as mock_date:
    mock_date.today.return_value = date(2010, 10, 8)
    mock_date.side_effect = lambda *args, **kw: date(*args, **kw)

How can I wrap this functionality into a one-line call?

Aucun commentaire:

Enregistrer un commentaire