mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
Adding support with xmlrunner for generating XML reports
This commit is contained in:
parent
d18bb876c7
commit
09dd71d056
@ -23,7 +23,7 @@ def testCaseLogger(message, logger=None):
|
||||
logger.debug(message)
|
||||
|
||||
class NoseTestExecuteEngine(object):
|
||||
def __init__(self, testclient=None, workingdir=None, clientLog=None, resultLog=None):
|
||||
def __init__(self, testclient=None, workingdir=None, clientLog=None, resultLog=None, format="text"):
|
||||
self.testclient = testclient
|
||||
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
|
||||
self.suite = []
|
||||
@ -53,10 +53,12 @@ class NoseTestExecuteEngine(object):
|
||||
self.injectTestCase(test)
|
||||
print self.suite[0].countTestCases()
|
||||
else:
|
||||
print "Single module test runs unsupported using Nose"
|
||||
raise
|
||||
|
||||
self.runner = nose.core.TextTestRunner(stream=self.testResultLogFile, descriptions=1, verbosity=2, config=None)
|
||||
raise Exception("Single module test runs unsupported using Nose")
|
||||
|
||||
if format == "text":
|
||||
self.runner = nose.core.TextTestRunner(stream=self.testResultLogFile, descriptions=1, verbosity=2, config=None)
|
||||
else:
|
||||
raise Exception("XML runner not supported under nose")
|
||||
|
||||
def runTests(self):
|
||||
#testProgram = nose.core.TestProgram(argv=["--process-timeout=3600"], testRunner = self.runner, testLoader = self.loader)
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
# Automatically generated by addcopyright.py at 04/03/2012
|
||||
|
||||
import unittest
|
||||
import xmlrunner
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
@ -22,7 +23,7 @@ def testCaseLogger(message, logger=None):
|
||||
logger.debug(message)
|
||||
|
||||
class TestCaseExecuteEngine(object):
|
||||
def __init__(self, testclient, testcaseLogFile=None, testResultLogFile=None):
|
||||
def __init__(self, testclient, testcaseLogFile=None, testResultLogFile=None, format="text"):
|
||||
"""
|
||||
Initialize the testcase execution engine, just the basics here
|
||||
@var testcaseLogFile: client log file
|
||||
@ -32,6 +33,7 @@ class TestCaseExecuteEngine(object):
|
||||
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
|
||||
self.loader = unittest.loader.TestLoader()
|
||||
self.suite = None
|
||||
self.format = format
|
||||
|
||||
if testcaseLogFile is not None:
|
||||
self.logfile = testcaseLogFile
|
||||
@ -82,4 +84,7 @@ class TestCaseExecuteEngine(object):
|
||||
|
||||
def run(self):
|
||||
if self.suite:
|
||||
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(self.suite)
|
||||
if self.format == "text":
|
||||
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(self.suite)
|
||||
elif self.format == "xml":
|
||||
xmlrunner.XMLTestRunner(output=self.testResultLogFile, verbose=True).run(self.suite)
|
||||
@ -26,6 +26,7 @@ if __name__ == "__main__":
|
||||
parser.add_option("-l", "--load", dest="load", action="store_true", help="only load config, do not deploy, it will only run testcase")
|
||||
parser.add_option("-f", "--file", dest="module", help="run tests in the given file")
|
||||
parser.add_option("-n", "--nose", dest="nose", action="store_true", help="run tests using nose")
|
||||
parser.add_option("-x", "--xml", dest="xmlrunner", action="store_true", help="use the xml runner to generate xml reports")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
testResultLogFile = None
|
||||
@ -40,6 +41,10 @@ if __name__ == "__main__":
|
||||
deploy.loadCfg()
|
||||
else:
|
||||
deploy.deploy()
|
||||
|
||||
format = "text"
|
||||
if options.xmlrunner:
|
||||
format = "xml"
|
||||
|
||||
if options.testCaseFolder is None:
|
||||
if options.module is None:
|
||||
@ -47,17 +52,17 @@ if __name__ == "__main__":
|
||||
exit(1)
|
||||
else:
|
||||
if options.nose:
|
||||
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
||||
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile, format)
|
||||
engine.runTestsFromFile(options.module)
|
||||
else:
|
||||
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
||||
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile, format)
|
||||
engine.loadTestsFromFile(options.module)
|
||||
engine.run()
|
||||
else:
|
||||
if options.nose:
|
||||
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, clientLog=testCaseLogFile, resultLog=testResultLogFile, workingdir=options.testCaseFolder)
|
||||
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, clientLog=testCaseLogFile, resultLog=testResultLogFile, workingdir=options.testCaseFolder, format=format)
|
||||
engine.runTests()
|
||||
else:
|
||||
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
||||
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile, format)
|
||||
engine.loadTestsFromDir(options.testCaseFolder)
|
||||
engine.run()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user