FIX: patch_environment restores pre-existing environment variables when finished (#1960)
Resolves #1832
This fixes a bug in patch_environment that currently leads to
pre-existing items being deleted completely from the environment
variables, when they were temporarily modified by patch_environment,
once the context has finished. Now, the env vars are restored to their
previous values.