suite: Set suite subdir lib part of syspath so tests can import their own modules
Change-Id: I3307c3ab314bb7a88d3c22c7c270c9f05fe6e03e
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index a7f91c5..44aabbd 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -148,9 +148,11 @@
self.reserved_resources = self.resources_pool.reserve(self, self.resource_requirements())
def run_tests(self, names=None):
+ suite_libdir = os.path.join(self.definition.suite_dir, 'lib')
try:
log.large_separator(self.trial.name(), self.name(), sublevel=2)
self.mark_start()
+ util.import_path_prepend(suite_libdir)
MainLoop.register_poll_func(self.poll)
if not self.reserved_resources:
self.reserve_resources()
@@ -177,6 +179,7 @@
self.objects_cleanup()
self.free_resources()
MainLoop.unregister_poll_func(self.poll)
+ util.import_path_remove(suite_libdir)
self.duration = time.time() - self.start_timestamp
passed, skipped, failed = self.count_test_results()
diff --git a/src/osmo_gsm_tester/util.py b/src/osmo_gsm_tester/util.py
index 8fe3029..c7efb77 100644
--- a/src/osmo_gsm_tester/util.py
+++ b/src/osmo_gsm_tester/util.py
@@ -112,6 +112,16 @@
if proc.result != 0:
raise RuntimeError('%s finished with err code %d' % (SETCAP_NET_ADMIN_BIN, proc.result))
+def import_path_prepend(pathname):
+ dir = os.path.realpath(pathname)
+ if dir not in sys.path:
+ sys.path.insert(0, dir)
+
+def import_path_remove(pathname):
+ dir = os.path.realpath(pathname)
+ if dir not in sys.path:
+ sys.path.remove(dir)
+
class listdict(dict):
'a dict of lists { "a": [1, 2, 3], "b": [1, 2] }'