This pattern will have side-effects that could cause errors if the tests are run multi-threaded or if the there is an error in the tear-down code. This might not be a problem depending on how Python unit tests get run. It may be worth double-checking with Craig Citro/John Asmuth to see if it is OK to have tests that modify the process environment like this. If not, this can be handled by having the product code go through an non-public overridable virtual call for things like checking the environment.