I have some tests and I need to patch a list in the module under test. I can directly blap it but I was hoping for something like patch.dict
For example I have code like this
with patch.dict(integrations.PARTNER_SERVICES, { some_key : some_config }):
self.do_foo()
And it cleans up properly after itself even if the test goes south. In this case I don't need to add an item to a dictionary but a list. I want to be able to use patch.list( in the same way I used patch.dict.
I am sure it is possible but what is the proper pythonic way?
Ok I feel kinda dumb but just figured out how to do it.
with patch.object(integrations, 'PARTNERS',[partner_type]):
self._do_stuff()
The name of the list is 'PARTNERS'. This seems blindingly obvious now.
Thanks for the patience in my learning process. Hopes this helps someone else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With