From cec8a0f154b8a4466df4c356fed1926f4434a8c7 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Wed, 8 May 2024 08:02:47 +0200 Subject: [PATCH] fix: retain os.environ obj in utils.sandboxed_env Previously bioconda_utils.utils.sandboxed_env assigned os.environ with a newly created dict and did not restore it to the original os.environ object -- breaking pytest.monkeypatch.setenv (and my sanity...). Signed-off-by: Marcel Bargull --- bioconda_utils/utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bioconda_utils/utils.py b/bioconda_utils/utils.py index 242fc7ea6e..031b9ef294 100644 --- a/bioconda_utils/utils.py +++ b/bioconda_utils/utils.py @@ -408,19 +408,18 @@ def sandboxed_env(env): the existing `os.environ` or the provided **env** that match ENV_VAR_WHITELIST globs. """ + os_environ = os.environ + orig = os_environ.copy() env = dict(env) - orig = os.environ.copy() - - _env = {k: v for k, v in orig.items() if allowed_env_var(k)} - _env.update({k: str(v) for k, v in env.items() if allowed_env_var(k)}) - - os.environ = _env try: + os_environ.clear() + os_environ.update({k: v for k, v in orig.items() if allowed_env_var(k)}) + os_environ.update({k: str(v) for k, v in env.items() if allowed_env_var(k)}) yield finally: - os.environ.clear() - os.environ.update(orig) + os_environ.clear() + os_environ.update(orig) def load_all_meta(recipe, config=None, finalize=True):