Skip to content

Commit

Permalink
Merge pull request #1806 from boegel/test_cache_eb_path
Browse files Browse the repository at this point in the history
cache $PATH & $PYTHONPATH in test setUp, restore them in tests where 'eb' is used
  • Loading branch information
boegel authored Jul 4, 2016
2 parents dc0d8e4 + 7045396 commit e25e05f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,9 @@ def test_include_generic_easyblocks(self):

def test_include_module_naming_schemes(self):
"""Test --include-module-naming-schemes."""
# make sure that calling out to 'eb' will work by restoring $PATH & $PYTHONPATH
self.restore_env_path_pythonpath()

fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
os.close(fd)

Expand Down Expand Up @@ -1970,6 +1973,9 @@ def test_use_included_module_naming_scheme(self):

def test_include_toolchains(self):
"""Test --include-toolchains."""
# make sure that calling out to 'eb' will work by restoring $PATH & $PYTHONPATH
self.restore_env_path_pythonpath()

fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
os.close(fd)

Expand Down
14 changes: 14 additions & 0 deletions test/framework/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ def setUp(self):
test_easyblocks_path = os.path.join(test_easyblocks_path, 'generic')
easybuild.easyblocks.generic.__path__.insert(0, test_easyblocks_path)

# save values of $PATH & $PYTHONPATH, so they can be restored later
# this is important in case EasyBuild was installed as a module, since that module may be unloaded,
# for example due to changes to $MODULEPATH in case EasyBuild was installed in a module hierarchy
# cfr. https://github.com/hpcugent/easybuild-framework/issues/1685
self.env_path = os.environ['PATH']
self.env_pythonpath = os.environ['PYTHONPATH']

self.modtool = modules_tool()
self.reset_modulepath([os.path.join(testdir, 'modules')])
reset_module_caches()
Expand Down Expand Up @@ -218,6 +225,13 @@ def tearDown(self):
# reset to make sure tempfile picks up new temporary directory to use
tempfile.tempdir = None

def restore_env_path_pythonpath(self):
"""
Restore $PATH & $PYTHONPATH in environment using saved values.
"""
os.environ['PATH'] = self.env_path
os.environ['PYTHONPATH'] = self.env_pythonpath

def reset_modulepath(self, modpaths):
"""Reset $MODULEPATH with specified paths."""
for modpath in curr_module_paths():
Expand Down

0 comments on commit e25e05f

Please sign in to comment.