Skip to content

Commit 6a5fca3

Browse files
authored
Merge pull request #3617 from ocaisa/set-EB_SCRIPT_PATH-in_tests
Make sure that path to eb is always found by tests
2 parents 1d502d5 + d68a495 commit 6a5fca3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

test/framework/easyconfig.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,11 @@ def test_get_paths_for(self):
33743374
self.mock_stderr(False)
33753375
self.assertTrue(os.path.samefile(test_ecs, res[0]))
33763376

3377+
# Can't have EB_SCRIPT_PATH set (for some of) these tests
3378+
env_eb_script_path = os.getenv('EB_SCRIPT_PATH')
3379+
if env_eb_script_path:
3380+
del os.environ['EB_SCRIPT_PATH']
3381+
33773382
# easyconfigs location can also be derived from location of 'eb'
33783383
write_file(os.path.join(self.test_prefix, 'bin', 'eb'), "#!/bin/bash; echo 'This is a fake eb'")
33793384
adjust_permissions(os.path.join(self.test_prefix, 'bin', 'eb'), stat.S_IXUSR)
@@ -3390,6 +3395,10 @@ def test_get_paths_for(self):
33903395
res = get_paths_for(subdir='easyconfigs', robot_path=None)
33913396
self.assertTrue(os.path.samefile(test_ecs, res[-1]))
33923397

3398+
# Restore (temporarily) EB_SCRIPT_PATH value if set originally
3399+
if env_eb_script_path:
3400+
os.environ['EB_SCRIPT_PATH'] = env_eb_script_path
3401+
33933402
# also locations in sys.path are considered
33943403
os.environ['PATH'] = orig_path
33953404
sys.path.insert(0, self.test_prefix)
@@ -3440,6 +3449,10 @@ def test_get_paths_for(self):
34403449
self.assertTrue(os.path.exists(res[0]))
34413450
self.assertTrue(os.path.samefile(res[0], os.path.join(someprefix, 'easybuild', 'easyconfigs')))
34423451

3452+
# Finally restore EB_SCRIPT_PATH value if set
3453+
if env_eb_script_path:
3454+
os.environ['EB_SCRIPT_PATH'] = env_eb_script_path
3455+
34433456
def test_is_generic_easyblock(self):
34443457
"""Test for is_generic_easyblock function."""
34453458

test/framework/utilities.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from easybuild.tools.config import GENERAL_CLASS, Singleton, module_classes
5151
from easybuild.tools.configobj import ConfigObj
5252
from easybuild.tools.environment import modify_env
53-
from easybuild.tools.filetools import copy_dir, mkdir, read_file
53+
from easybuild.tools.filetools import copy_dir, mkdir, read_file, which
5454
from easybuild.tools.modules import curr_module_paths, modules_tool, reset_module_caches
5555
from easybuild.tools.options import CONFIG_ENV_VAR_PREFIX, EasyBuildOptions, set_tmpdir
5656
from easybuild.tools.py2vs3 import reload
@@ -124,6 +124,12 @@ def setUp(self):
124124
# make sure that the tests only pick up easyconfigs provided with the tests
125125
os.environ['EASYBUILD_ROBOT_PATHS'] = os.path.join(testdir, 'easyconfigs', 'test_ecs')
126126

127+
# make sure that the EasyBuild installation is still known even if we purge an EB module
128+
if os.getenv('EB_SCRIPT_PATH') is None:
129+
eb_path = which('eb')
130+
if eb_path is not None:
131+
os.environ['EB_SCRIPT_PATH'] = eb_path
132+
127133
# make sure no deprecated behaviour is being triggered (unless intended by the test)
128134
self.orig_current_version = eb_build_log.CURRENT_VERSION
129135
self.disallow_deprecated_behaviour()

0 commit comments

Comments
 (0)