diff --git a/reframe/utility/__init__.py b/reframe/utility/__init__.py index ae0bb6152c..d1f603ad63 100644 --- a/reframe/utility/__init__.py +++ b/reframe/utility/__init__.py @@ -44,6 +44,9 @@ def import_module_from_file(filename): if os.path.isdir(filename): filename = os.path.join(filename, '__init__.py') + if filename.startswith('..'): + filename = os.path.abspath(filename) + module_name = _get_module_name(filename) if os.path.isabs(filename): return _do_import_module_from_file(filename, module_name) diff --git a/unittests/test_utility.py b/unittests/test_utility.py index f1a40fa634..4cb2576c57 100644 --- a/unittests/test_utility.py +++ b/unittests/test_utility.py @@ -280,6 +280,20 @@ def test_load_unknown_path(self): self.assertEqual('foo', e.name) self.assertEqual('/foo', e.path) + def test_load_directory_relative(self): + with os_ext.change_dir('reframe'): + module = util.import_module_from_file('../reframe') + self.assertEqual(reframe.VERSION, module.VERSION) + self.assertEqual('reframe', module.__name__) + self.assertIs(module, sys.modules.get('reframe')) + + def test_load_file_relative(self): + with os_ext.change_dir('reframe'): + module = util.import_module_from_file('../reframe/__init__.py') + self.assertEqual(reframe.VERSION, module.VERSION) + self.assertEqual('reframe', module.__name__) + self.assertIs(module, sys.modules.get('reframe')) + def test_load_twice(self): filename = os.path.abspath('reframe/__init__.py') module1 = util.import_module_from_file(filename)