Files
galaxy/test/unit/tool_util/util.py
T
Sergey Golitsynskiy 0e4e1d9249 Restructure unit tests for tool_util package
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/.
2019-07-16 20:15:45 -04:00

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)