From 09dd71d0569261eda762684d9b0cbe4ed914c778 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Fri, 18 May 2012 12:04:11 +0530 Subject: [PATCH] Adding support with xmlrunner for generating XML reports --- tools/marvin/marvin/NoseTestExecuteEngine.py | 12 +++++++----- tools/marvin/marvin/TestCaseExecuteEngine.py | 9 +++++++-- tools/marvin/marvin/deployAndRun.py | 13 +++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/marvin/marvin/NoseTestExecuteEngine.py b/tools/marvin/marvin/NoseTestExecuteEngine.py index 1dda2d87cc4..8ad34bb91ae 100644 --- a/tools/marvin/marvin/NoseTestExecuteEngine.py +++ b/tools/marvin/marvin/NoseTestExecuteEngine.py @@ -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) diff --git a/tools/marvin/marvin/TestCaseExecuteEngine.py b/tools/marvin/marvin/TestCaseExecuteEngine.py index 996a7e9f4b1..67ed14a6aab 100644 --- a/tools/marvin/marvin/TestCaseExecuteEngine.py +++ b/tools/marvin/marvin/TestCaseExecuteEngine.py @@ -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) \ No newline at end of file diff --git a/tools/marvin/marvin/deployAndRun.py b/tools/marvin/marvin/deployAndRun.py index 01f106d5243..e7d9e6120b2 100644 --- a/tools/marvin/marvin/deployAndRun.py +++ b/tools/marvin/marvin/deployAndRun.py @@ -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()