<div dir="ltr"><div><div><br>On Tue, Mar 29, 2016 at 6:49 AM, Pietro <<a href="mailto:peter.zamb@gmail.com">peter.zamb@gmail.com</a>> wrote:<br>><br>> 1. overwrite the environment variables,<br>> 2. execute the test and<br>> 3. restore the environment variables.<br><br><br>In case the test involves just calling subprocesses, the best way probably is to change their environment instead of changing the global one. This is not applicable to function calls of course.<br> <br>> Otherwise if the function raise an exception the current<br>> implementation will not restore the environment variables back to<br>> their original value.<br><br><br></div>Although I can see advantages of decorators, Python unittest package uses setUp() and tearDown() functions for that purpose. Introducing another mechanism might interfere with the execution of the tests. If nothing else, you would need to re-raise the exception to signal that the test failed. I suggest to try setUp() and tearDown() as unittest advocates and only when it won't work look at decorators (which are used in unittest but it different way).<br><br></div>Vaclav<br></div>