Skip to content

Commit

Permalink
Restore environment after sub-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Feb 19, 2025
1 parent b3c10b7 commit 0876b63
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@author: Maxime Boissonneault (Compute Canada)
@author: Jan Andre Reuter (Juelich Supercomputing Centre)
"""
import copy
import os
import re
import shutil
Expand All @@ -49,6 +50,7 @@
from easybuild.tools import LooseVersion, config
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import get_module_syntax, update_build_option
from easybuild.tools.environment import modify_env
from easybuild.tools.filetools import change_dir, copy_dir, copy_file, mkdir, read_file, remove_dir, remove_file
from easybuild.tools.filetools import verify_checksum, write_file
from easybuild.tools.module_generator import module_generator
Expand Down Expand Up @@ -2311,17 +2313,23 @@ def test_extension_patch_step(self):

cwd = os.getcwd()
self.assertExists(cwd)
# Take environment with test-specific variable set up
orig_environ = copy.deepcopy(os.environ)

def run_extension_step():
change_dir(cwd)
eb = EasyBlock(ec)
# Cleanup build directory
if os.path.exists(eb.builddir):
remove_dir(eb.builddir)
eb.make_builddir()
eb.update_config_template_run_step()
eb.extensions_step(fetch=True, install=True)
return os.path.join(eb.builddir)
try:
change_dir(cwd)
eb = EasyBlock(ec)
# Cleanup build directory
if os.path.exists(eb.builddir):
remove_dir(eb.builddir)
eb.make_builddir()
eb.update_config_template_run_step()
eb.extensions_step(fetch=True, install=True)
return os.path.join(eb.builddir)
finally:
# restore original environment to continue testing with a clean slate
modify_env(os.environ, orig_environ, verbose=False)

ec['exts_defaultclass'] = 'DummyExtension'
ec['exts_list'] = [('toy', '0.0', {'easyblock': 'DummyExtension'})]
Expand Down

0 comments on commit 0876b63

Please sign in to comment.