Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasileios Karakasis committed Jan 21, 2022
1 parent b487095 commit 2955791
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions reframe/utility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ def import_module_from_file(filename, force=False):
module_name = _get_module_name(rel_filename)
if rel_filename.startswith('..'):
# We cannot use the standard Python import mechanism here, because the
# module to import is outside the top-level package
# module to import is outside the top-level package. We also mangle
# the name that we assign to the module, in order to avoid clashes
# with other modules loaded with a standard `import` or with multiple
# test files with the same name that reside in different directories.
module_hash = sha256(filename.encode('utf-8')).hexdigest()[:8]
module_name = f'rfm_{module_name}_{module_hash}'

module_name = f'{module_name}@{module_hash}'
return _do_import_module_from_file(filename, module_name)

# Extract module name if `filename` is under `site-packages/` or the
Expand Down
1 change: 0 additions & 1 deletion unittests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def test_load_fixtures(loader):


def test_existing_module_name(loader, tmp_path):
print(type(tmp_path))
test_file = tmp_path / 'os.py'
shutil.copyfile('unittests/resources/checks/emptycheck.py', test_file)
checks = loader.load_from_file(test_file)
Expand Down
4 changes: 2 additions & 2 deletions unittests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ def test_import_from_file_existing_module_name(tmp_path):

module = util.import_module_from_file(test_file)
assert module.var == 1
assert not hasattr(module, 'abc')
assert hasattr(os, 'abc')
assert not hasattr(module, 'path')
assert hasattr(os, 'path')


def test_import_from_file_load_directory_relative():
Expand Down

0 comments on commit 2955791

Please sign in to comment.