Support added for attrib, multiprocess and Xunit coverage plugins

Conflicts:

	tools/marvin/marvin/NoseTestExecuteEngine.py
This commit is contained in:
Prasanna Santhanam 2012-07-20 17:26:42 +05:30 committed by Prasanna Santhanam
parent 84b69e6e0a
commit 0ab7a9289f
2 changed files with 27 additions and 50 deletions

View File

@ -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)

View File

@ -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):