Permalink
Browse files

virttest.common: Fix unittest execution

Follow the same schema used in the kvm, libvirt and v2v
subfolders, so the code can actually find an autotest
checkout to import modules from.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
  • Loading branch information...
1 parent 86e28a6 commit 003344ede7ade027cc2556b54e1e03e9d290e108 @lmr lmr committed Sep 30, 2012
Showing with 30 additions and 7 deletions.
  1. +30 −7 virttest/common.py
View
@@ -1,8 +1,31 @@
import os, sys
-dirname = os.path.dirname(sys.modules[__name__].__file__)
-client_dir = os.path.abspath(os.path.join(dirname, "..", "..", ".."))
-sys.path.insert(0, client_dir)
-import setup_modules
-sys.path.pop(0)
-setup_modules.setup(base_path=client_dir,
- root_module_name="autotest.client")
+
+def load_setup_modules(client_dir):
+ try:
+ sys.path.insert(0, client_dir)
+ import setup_modules
+ finally:
+ sys.path.pop(0)
+ return setup_modules
+
+try:
+ import autotest.client.setup_modules as setup_modules
+ client_dir = os.path.dirname(setup_modules.__file__)
+ sm = setup_modules
+except ImportError:
+ dirname = os.path.dirname(sys.modules[__name__].__file__)
+ try:
+ client_dir = os.path.abspath(os.path.join(dirname, "..", "..", ".."))
+ sm = load_setup_modules(client_dir)
+ except:
+ try:
+ client_dir = os.path.join(os.environ['AUTOTEST_PATH'], 'client')
+ except KeyError:
+ print("Environment variable $AUTOTEST_PATH not set. "
+ "please set it to a path containing an autotest checkout")
+ sys.exit(1)
+ sm = load_setup_modules(client_dir)
+ virt_test_dir = os.path.abspath(os.path.join(dirname, ".."))
+ sys.path.insert(0, virt_test_dir)
+
+sm.setup(base_path=client_dir, root_module_name="autotest.client")

0 comments on commit 003344e

Please sign in to comment.