You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2012/07/30 12:07:19 UTC

[9/16] git commit: injecting the testclient during Test Loader process

injecting the testclient during Test Loader process

Without this the tests do not have access to the client APIs


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/84b69e6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/84b69e6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/84b69e6e

Branch: refs/heads/master
Commit: 84b69e6e0a8fc99ac57d3024acadc3cd35ec3f79
Parents: db5687d
Author: Prasanna Santhanam <Pr...@citrix.com>
Authored: Sat Jul 7 21:51:08 2012 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Mon Jul 30 15:32:33 2012 +0530

----------------------------------------------------------------------
 tools/marvin/marvin/NoseTestExecuteEngine.py |   48 ++++++++++++---------
 1 files changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/84b69e6e/tools/marvin/marvin/NoseTestExecuteEngine.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/NoseTestExecuteEngine.py b/tools/marvin/marvin/NoseTestExecuteEngine.py
index 9d7944a..9499c90 100644
--- a/tools/marvin/marvin/NoseTestExecuteEngine.py
+++ b/tools/marvin/marvin/NoseTestExecuteEngine.py
@@ -40,6 +40,7 @@ class NoseCloudStackTestLoader(nose.loader.TestLoader):
             tests = []
             for testCaseName in testCaseNames:
                 testCase = testCaseClass(testCaseName)
+                self._injectClients(testCase)
                 tests.append(testCase)
             return self.suiteClass(tests)
         else:
@@ -50,7 +51,25 @@ class NoseCloudStackTestLoader(nose.loader.TestLoader):
     
     def loadTestsFromNames(self, names, module=None):
         return nose.loader.TestLoader.loadTestsFromNames(self, names, module=module)
-            
+
+    def setClient(self, client):
+        self.testclient = client
+
+    def setClientLog(self, clientlog):
+        self.log = clientlog
+
+    def _injectClients(self, test):
+        testcaselogger = logging.getLogger("testclient.testcase.%s"%test.__class__.__name__)
+        fh = logging.FileHandler(self.log) 
+        fh.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s"))
+        testcaselogger.addHandler(fh)
+        testcaselogger.setLevel(logging.DEBUG)
+        
+        setattr(test, "testClient", self.testclient)
+        setattr(test, "debug", partial(testCaseLogger, logger=testcaselogger))
+        setattr(test.__class__, "clstestclient", self.testclient)
+        if hasattr(test, "UserName"):
+            self.testclient.createNewApiClient(test.UserName, test.DomainName, test.AcctType)           
 
 class NoseTestExecuteEngine(object):
     """
@@ -81,14 +100,14 @@ class NoseTestExecuteEngine(object):
  
         if workingdir is not None:
             self.loader = NoseCloudStackTestLoader()
-            self.suite = self.loader.loadTestsFromName(workingdir)
-            for test in self.suite:
-                self.injectClients(test)
+            self.loader.setClient(self.testclient)
+            self.loader.setClientLog(self.logfile)
+            self.suite = self.loader.loadTestsFromDir(workingdir)
         elif filename is not None:
             self.loader = NoseCloudStackTestLoader()
+            self.loader.setClient(self.testclient)
+            self.loader.setClientLog(self.logfile)
             self.suite = self.loader.loadTestsFromFile(filename)
-            for test in self.suite:
-                self.injectClients(test)
         else:
             raise EnvironmentError("Need to give either a test directory or a test file")
         
@@ -98,17 +117,6 @@ class NoseTestExecuteEngine(object):
             self.runner = xmlrunner.XMLTestRunner(output='xml-reports', verbose=True)
             
     def runTests(self):
-         nose.core.TestProgram(argv=["--process-timeout=3600"], testRunner=self.runner, testLoader=self.loader)
-        
-    def injectClients(self, test):
-        testcaselogger = logging.getLogger("testclient.testcase.%s"%test.__class__.__name__)
-        fh = logging.FileHandler(self.logfile) 
-        fh.setFormatter(self.logformat)
-        testcaselogger.addHandler(fh)
-        testcaselogger.setLevel(logging.DEBUG)
-        
-        setattr(test, "testClient", self.testclient)
-        setattr(test, "debug", partial(testCaseLogger, logger=testcaselogger))
-        setattr(test.__class__, "clstestclient", self.testclient)
-        if hasattr(test, "UserName"):
-            self.testclient.createNewApiClient(test.UserName, test.DomainName, test.AcctType)
+         #nose.core.TestProgram(argv=["--process-timeout=3600"], testRunner=self.runner, testLoader=self.loader)
+         nose.core.TestProgram(argv=["--process-timeout=3600"], \
+                               testRunner=self.runner, suite=self.suite)