Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In python is there a way to patch a list similiar to using patch.dict?

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?

like image 774
danielrr Avatar asked Mar 18 '23 20:03

danielrr


1 Answers

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.

like image 97
danielrr Avatar answered Apr 08 '23 19:04

danielrr