Extracting environment patcher
Correct test assertion
Meant 'items'
Avoid passing None values to os.environ.
Add docstring
Always restore os.environ even if an exception occurs.