[PATCH] osmo-gsm-tester[master]: suite: Set suite subdir lib part of syspath so tests can imp...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Tue May 8 15:14:44 UTC 2018


Review at  https://gerrit.osmocom.org/8067

suite: Set suite subdir lib part of syspath so tests can import their own modules

Change-Id: I3307c3ab314bb7a88d3c22c7c270c9f05fe6e03e
---
M src/osmo_gsm_tester/suite.py
M src/osmo_gsm_tester/util.py
2 files changed, 13 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/67/8067/1

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] }'
 

-- 
To view, visit https://gerrit.osmocom.org/8067
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3307c3ab314bb7a88d3c22c7c270c9f05fe6e03e
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list