From: Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: Fix subtest imports Date: Wed, 2 Dec 2009 01:26:19 -0200 Message-ID: <1259724379-6883-1-git-send-email-lmr@redhat.com> Cc: kvm@vger.kernel.org, mgoldish@redhat.com, Lucas Meneghel Rodrigues To: autotest@test.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:29272 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754283AbZLBD0S (ORCPT ); Tue, 1 Dec 2009 22:26:18 -0500 Sender: kvm-owner@vger.kernel.org List-ID: The KVM test was breaking when trying to import the subtest 'autotest', as a naming clash was happening (client/bin/autotest was being imported instead of the autotest subtest), so to make naming clashes less likely, import test.[type] instead of just [type]. Also, as the kvm test was already inserted to sys.path on the control file, don't add additional cruft to the library search path. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm.py | 22 +++++++++------------- 1 files changed, 9 insertions(+), 13 deletions(-) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index 06ef9f5..332fa86 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -22,9 +22,7 @@ class kvm(test.test): """ version = 1 def initialize(self): - # Make it possible to import modules from the subtest dir self.subtest_dir = os.path.join(self.bindir, 'tests') - sys.path.append(self.subtest_dir) def run_once(self, params): @@ -44,23 +42,20 @@ class kvm(test.test): try: try: # Get the test routine corresponding to the specified test type - type = params.get("type") + t_type = params.get("type") # Verify if we have the correspondent source file for it - module_path = os.path.join(self.subtest_dir, '%s.py' % type) + module_path = os.path.join(self.subtest_dir, '%s.py' % t_type) if not os.path.isfile(module_path): - raise error.TestError("No %s.py test file found" % type) - # Load the tests directory (which was turned into a py module) - try: - test_module = __import__(type) - except ImportError, e: - raise error.TestError("Failed to import test %s: %s" % - (type, e)) - + raise error.TestError("No %s.py test file found" % t_type) + # Load the test module + # (KVM test dir was appended to sys.path in the control file) + __import__("tests.%s" % t_type) + test_module = sys.modules["tests.%s" % t_type] # Preprocess kvm_preprocessing.preprocess(self, params, env) kvm_utils.dump_env(env, env_filename) # Run the test function - run_func = getattr(test_module, "run_%s" % type) + run_func = getattr(test_module, "run_%s" % t_type) run_func(self, params, env) kvm_utils.dump_env(env, env_filename) @@ -76,3 +71,4 @@ class kvm(test.test): kvm_preprocessing.postprocess(self, params, env) logging.debug("Contents of environment: %s", str(env)) kvm_utils.dump_env(env, env_filename) + -- 1.6.5.2