I am writing a test for some code that checks for a value in os.environ
(I know this isn't optimal, but I have to go with it). I would like to remove an entry from os.environ for the duration of the test. I am not sure if mock supports this. I know patch.dict
can be used to modify an item, but I want the key/value pair removed. I would like something along these lines:
print os.environ
{ ... , 'MY_THING': 'foo', ... }
with mock.patch.dict.delete('os.environ', 'MY_THING'):
# run the test
# ( 'MY_THING' in os.environ ) should return False
# everything back to normal now
print os.environ
{ ... , 'MY_THING': 'foo', ... }
Is there a way to perform such a feat?
Aucun commentaire:
Enregistrer un commentaire