Skip to content

Commit

Permalink
Correctly restore sys.path in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Jul 28, 2021
1 parent 77c5e5b commit 541c41f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion test/framework/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ def test_flex_robot_paths(self):

# prepend path to test easyconfigs into Python search path, so it gets picked up as --robot-paths default
orig_sys_path = sys.path[:]
sys.path = [tmpdir] + [p for p in sys.path if not os.path.exists(os.path.join(p, 'easybuild', 'easyconfigs'))]
sys.path[:] = [tmpdir] + [
p for p in sys.path if not os.path.exists(os.path.join(p, 'easybuild', 'easyconfigs'))
]

# default: only pick up installed easyconfigs via sys.path
eb_go = eboptions.parse_options(args=[])
Expand Down
2 changes: 1 addition & 1 deletion test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3527,7 +3527,7 @@ def test_get_paths_for(self):
self.assertEqual(res[-1], os.path.join(symlinked_prefix, 'easybuild', 'easyconfigs'))

# wipe sys.path. then only path found via $EB_SCRIPT_PATH is found
sys.path = []
sys.path[:] = []
res = get_paths_for(subdir='easyconfigs', robot_path=None)
self.assertEqual(len(res), 1)
self.assertEqual(res[0], os.path.join(symlinked_prefix, 'easybuild', 'easyconfigs'))
Expand Down
8 changes: 4 additions & 4 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,7 @@ def test_xxx_include_easyblocks(self):

# 'undo' import of foo easyblock
del sys.modules['easybuild.easyblocks.foo']
sys.path = orig_local_sys_path
sys.path[:] = orig_local_sys_path
import easybuild.easyblocks
reload(easybuild.easyblocks)
import easybuild.easyblocks.generic
Expand Down Expand Up @@ -3333,7 +3333,7 @@ def test_xxx_include_generic_easyblocks(self):
# 'undo' import of foobar easyblock
del sys.modules['easybuild.easyblocks.generic.foobar']
os.remove(os.path.join(self.test_prefix, 'generic', 'foobar.py'))
sys.path = orig_local_sys_path
sys.path[:] = orig_local_sys_path
import easybuild.easyblocks
reload(easybuild.easyblocks)
import easybuild.easyblocks.generic
Expand Down Expand Up @@ -3432,7 +3432,7 @@ def test_github_xxx_include_easyblocks_from_pr(self):
del sys.modules['easybuild.easyblocks.foo']
del sys.modules['easybuild.easyblocks.generic.cmakemake']
os.remove(os.path.join(self.test_prefix, 'foo.py'))
sys.path = orig_local_sys_path
sys.path[:] = orig_local_sys_path

# include test cmakemake easyblock
cmm_txt = '\n'.join([
Expand Down Expand Up @@ -3491,7 +3491,7 @@ def test_github_xxx_include_easyblocks_from_pr(self):
del sys.modules['easybuild.easyblocks.foo']
del sys.modules['easybuild.easyblocks.generic.cmakemake']
os.remove(os.path.join(self.test_prefix, 'cmakemake.py'))
sys.path = orig_local_sys_path
sys.path[:] = orig_local_sys_path
import easybuild.easyblocks
reload(easybuild.easyblocks)
import easybuild.easyblocks.generic
Expand Down
2 changes: 1 addition & 1 deletion test/framework/toy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_toy_build_with_blocks(self):

# cleanup
shutil.rmtree(tmpdir)
sys.path = orig_sys_path
sys.path[:] = orig_sys_path

def test_toy_build_formatv2_sections(self):
"""Perform a toy build (format v2, using sections)."""
Expand Down
2 changes: 1 addition & 1 deletion test/framework/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def tearDown(self):
self.allow_deprecated_behaviour()

# restore original Python search path
sys.path = self.orig_sys_path
sys.path[:] = self.orig_sys_path
import easybuild.easyblocks
reload(easybuild.easyblocks)
import easybuild.easyblocks.generic
Expand Down

0 comments on commit 541c41f

Please sign in to comment.