mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-13 08:51:38 +08:00
This replaces a previous (now closed) PR: https://github.com/galaxyproject/galaxy/pull/8279 A few changes: - tests for code in galaxy/tool_util moved under test/unit/tool_util - common parts (used in both tools and tool_util) factored out into unittest_utils/sample_data.py - symlink to sample_data.py in test/unit/tool_util/ is needed to make the tool_util package tests run. This is not an ideal solution, but it avoids duplication of the sample data used by tests in tools/ and tool_util/.
23 lines
623 B
Python
23 lines
623 B
Python
from contextlib import contextmanager
|
|
from os import environ
|
|
|
|
|
|
@contextmanager
|
|
def modify_environ(values, keys_to_remove=None):
|
|
"""
|
|
Modify the environment for a test, adding/updating values in dict `values` and
|
|
removing any environment variables mentioned in list `keys_to_remove`.
|
|
"""
|
|
old_environ = environ.copy()
|
|
try:
|
|
if values:
|
|
environ.update(values)
|
|
if keys_to_remove:
|
|
for key in keys_to_remove:
|
|
if key in environ:
|
|
del environ[key]
|
|
yield
|
|
finally:
|
|
environ.clear()
|
|
environ.update(old_environ)
|