jeudi 18 juillet 2019

Difference between monkeypatch and patch?

I'm using pytest and want to mock the return value of the stripe.PaymentIntent.create method.

Both versions below are working but I wonder if there is a difference I don't understand or is it the same just written in another way.

Using the pytest fixture monkeypatch:

monkeypatch.setattr(
    'stripe.PaymentIntent.create', lambda *args, **kwargs: Mock(status='succeeded')
)

Using patch from unittest:

mock.patch('stripe.PaymentIntent.create', return_value=Mock(status='succeeded'))

Aucun commentaire:

Enregistrer un commentaire