mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +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)
|
logger.debug(message)
|
||||||
|
|
||||||
class NoseTestExecuteEngine(object):
|
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.testclient = testclient
|
||||||
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
|
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
|
||||||
self.suite = []
|
self.suite = []
|
||||||
@ -53,10 +53,12 @@ class NoseTestExecuteEngine(object):
|
|||||||
self.injectTestCase(test)
|
self.injectTestCase(test)
|
||||||
print self.suite[0].countTestCases()
|
print self.suite[0].countTestCases()
|
||||||
else:
|
else:
|
||||||
print "Single module test runs unsupported using Nose"
|
raise Exception("Single module test runs unsupported using Nose")
|
||||||
raise
|
|
||||||
|
if format == "text":
|
||||||
self.runner = nose.core.TextTestRunner(stream=self.testResultLogFile, descriptions=1, verbosity=2, config=None)
|
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):
|
def runTests(self):
|
||||||
#testProgram = nose.core.TestProgram(argv=["--process-timeout=3600"], testRunner = self.runner, testLoader = self.loader)
|
#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
|
# Automatically generated by addcopyright.py at 04/03/2012
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import xmlrunner
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
@ -22,7 +23,7 @@ def testCaseLogger(message, logger=None):
|
|||||||
logger.debug(message)
|
logger.debug(message)
|
||||||
|
|
||||||
class TestCaseExecuteEngine(object):
|
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
|
Initialize the testcase execution engine, just the basics here
|
||||||
@var testcaseLogFile: client log file
|
@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.logformat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
|
||||||
self.loader = unittest.loader.TestLoader()
|
self.loader = unittest.loader.TestLoader()
|
||||||
self.suite = None
|
self.suite = None
|
||||||
|
self.format = format
|
||||||
|
|
||||||
if testcaseLogFile is not None:
|
if testcaseLogFile is not None:
|
||||||
self.logfile = testcaseLogFile
|
self.logfile = testcaseLogFile
|
||||||
@ -82,4 +84,7 @@ class TestCaseExecuteEngine(object):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.suite:
|
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("-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("-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("-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()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
testResultLogFile = None
|
testResultLogFile = None
|
||||||
@ -40,6 +41,10 @@ if __name__ == "__main__":
|
|||||||
deploy.loadCfg()
|
deploy.loadCfg()
|
||||||
else:
|
else:
|
||||||
deploy.deploy()
|
deploy.deploy()
|
||||||
|
|
||||||
|
format = "text"
|
||||||
|
if options.xmlrunner:
|
||||||
|
format = "xml"
|
||||||
|
|
||||||
if options.testCaseFolder is None:
|
if options.testCaseFolder is None:
|
||||||
if options.module is None:
|
if options.module is None:
|
||||||
@ -47,17 +52,17 @@ if __name__ == "__main__":
|
|||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
if options.nose:
|
if options.nose:
|
||||||
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile, format)
|
||||||
engine.runTestsFromFile(options.module)
|
engine.runTestsFromFile(options.module)
|
||||||
else:
|
else:
|
||||||
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile, format)
|
||||||
engine.loadTestsFromFile(options.module)
|
engine.loadTestsFromFile(options.module)
|
||||||
engine.run()
|
engine.run()
|
||||||
else:
|
else:
|
||||||
if options.nose:
|
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()
|
engine.runTests()
|
||||||
else:
|
else:
|
||||||
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile, format)
|
||||||
engine.loadTestsFromDir(options.testCaseFolder)
|
engine.loadTestsFromDir(options.testCaseFolder)
|
||||||
engine.run()
|
engine.run()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user