From 0ab7a9289f52acc3f25f92984c9508684c1321fd Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Fri, 20 Jul 2012 17:26:42 +0530 Subject: [PATCH] Support added for attrib, multiprocess and Xunit coverage plugins Conflicts: tools/marvin/marvin/NoseTestExecuteEngine.py --- tools/marvin/marvin/NoseTestExecuteEngine.py | 75 +++++++------------- tools/marvin/marvin/cloudstackTestCase.py | 2 +- 2 files changed, 27 insertions(+), 50 deletions(-) diff --git a/tools/marvin/marvin/NoseTestExecuteEngine.py b/tools/marvin/marvin/NoseTestExecuteEngine.py index 9499c9032a4..25d5c9343e9 100644 --- a/tools/marvin/marvin/NoseTestExecuteEngine.py +++ b/tools/marvin/marvin/NoseTestExecuteEngine.py @@ -24,52 +24,10 @@ import sys import logging import xmlrunner from cloudstackTestCase import cloudstackTestCase - -def testCaseLogger(message, logger=None): - if logger is not None: - logger.debug(message) - -class NoseCloudStackTestLoader(nose.loader.TestLoader): - """ - Custom test loader for the cloudstackTestCase to be loaded into nose - """ - - def loadTestsFromTestCase(self, testCaseClass): - if issubclass(testCaseClass, cloudstackTestCase): - testCaseNames = self.getTestCaseNames(testCaseClass) - tests = [] - for testCaseName in testCaseNames: - testCase = testCaseClass(testCaseName) - self._injectClients(testCase) - tests.append(testCase) - return self.suiteClass(tests) - else: - return super(NoseCloudStackTestLoader, self).loadTestsFromTestCase(testCaseClass) - - def loadTestsFromName(self, name, module=None, discovered=False): - return nose.loader.TestLoader.loadTestsFromName(self, name, module=module, discovered=discovered) - - 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) +from marvinPlugin import MarvinPlugin +from nose.plugins.xunit import Xunit +from nose.plugins.attrib import AttributeSelector +from nose.plugins.multiprocess import MultiProcessTestRunner class NoseTestExecuteEngine(object): """ @@ -111,12 +69,31 @@ class NoseTestExecuteEngine(object): else: raise EnvironmentError("Need to give either a test directory or a test file") + plug_mgr = nose.plugins.manager.PluginManager() + plug_mgr.addPlugin(self.test_picker) + plug_mgr.addPlugin(Xunit()) + plug_mgr.addPlugin(AttributeSelector()) + plug_mgr.addPlugin(MultiProcessTestRunner()) + self.cfg = nose.config.Config() + self.cfg.plugins = plug_mgr + if format == "text": self.runner = nose.core.TextTestRunner(stream=self.testResultLogFile, descriptions=1, verbosity=2, config=None) else: 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) - nose.core.TestProgram(argv=["--process-timeout=3600"], \ - testRunner=self.runner, suite=self.suite) + options = ["--process-timeout=3600", "--with-xunit", "-a tags=advanced", "--processes=5"] #TODO: Add support for giving nose args + #DEBUG +# options = ["--process-timeout=3600", "--with-xunit", "--collect-only"] + #DEBUG +# options = ["--process-timeout=3600"] + options.append("-w%s" %self.workingdir) + + if self.workingdir is not None: + nose.core.TestProgram(argv=options, testRunner=self.runner, + config=self.cfg) + elif self.filename is not None: + tests = self.loader.loadTestsFromFile(self.filename) + nose.core.TestProgram(argv=options, testRunner=self.runner, + config=self.cfg) diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index a85eef7e1dd..4ec764c58bf 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -48,7 +48,7 @@ class cloudstackTestCase(unittest.case.TestCase): def __init__(self, args): unittest.case.TestCase.__init__(self, args) - self.testClient = cloudstackTestClient.cloudstackTestClient() +# self.testClient = cloudstackTestClient.cloudstackTestClient() @classmethod def getClsTestClient(cls):