mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 02:22:52 +01:00
support for running tests in a given script
This commit is contained in:
parent
dba1c01cb5
commit
a0efa70958
@ -25,10 +25,16 @@ def testCaseLogger(message, logger=None):
|
|||||||
logger.debug(message)
|
logger.debug(message)
|
||||||
|
|
||||||
class TestCaseExecuteEngine(object):
|
class TestCaseExecuteEngine(object):
|
||||||
def __init__(self, testclient, testCaseFolder, testcaseLogFile=None, testResultLogFile=None):
|
def __init__(self, testclient, testcaseLogFile=None, testResultLogFile=None):
|
||||||
|
"""
|
||||||
|
Initialize the testcase execution engine, just the basics here
|
||||||
|
@var testcaseLogFile: client log file
|
||||||
|
@var testResultLogFile: summary report file
|
||||||
|
"""
|
||||||
self.testclient = testclient
|
self.testclient = testclient
|
||||||
self.testCaseFolder = testCaseFolder
|
|
||||||
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.suite = None
|
||||||
|
|
||||||
if testcaseLogFile is not None:
|
if testcaseLogFile is not None:
|
||||||
self.logfile = testcaseLogFile
|
self.logfile = testcaseLogFile
|
||||||
@ -46,7 +52,18 @@ class TestCaseExecuteEngine(object):
|
|||||||
self.testResultLogFile = fp
|
self.testResultLogFile = fp
|
||||||
else:
|
else:
|
||||||
self.testResultLogFile = sys.stdout
|
self.testResultLogFile = sys.stdout
|
||||||
|
|
||||||
|
def loadTestsFromDir(self, testDirectory):
|
||||||
|
""" Load the test suites from a package with multiple test files """
|
||||||
|
self.suite = self.loader.discover(testDirectory)
|
||||||
|
self.injectTestCase(self.suite)
|
||||||
|
|
||||||
|
def loadTestsFromFile(self, file_name):
|
||||||
|
""" Load the tests from a single script/module """
|
||||||
|
if os.path.isfile(file_name):
|
||||||
|
self.suite = self.loader.discover(os.path.dirname(file_name), os.path.basename(file_name))
|
||||||
|
self.injectTestCase(self.suite)
|
||||||
|
|
||||||
def injectTestCase(self, testSuites):
|
def injectTestCase(self, testSuites):
|
||||||
for test in testSuites:
|
for test in testSuites:
|
||||||
if isinstance(test, unittest.BaseTestSuite):
|
if isinstance(test, unittest.BaseTestSuite):
|
||||||
@ -67,8 +84,5 @@ class TestCaseExecuteEngine(object):
|
|||||||
self.testclient.createNewApiClient(test.UserName, test.DomainName, test.AcctType)
|
self.testclient.createNewApiClient(test.UserName, test.DomainName, test.AcctType)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
loader = unittest.loader.TestLoader()
|
if self.suite:
|
||||||
suite = loader.discover(self.testCaseFolder)
|
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(self.suite)
|
||||||
self.injectTestCase(suite)
|
|
||||||
|
|
||||||
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(suite)
|
|
||||||
|
|||||||
@ -12,21 +12,22 @@
|
|||||||
# Automatically generated by addcopyright.py at 04/03/2012
|
# Automatically generated by addcopyright.py at 04/03/2012
|
||||||
import deployDataCenter
|
import deployDataCenter
|
||||||
import TestCaseExecuteEngine
|
import TestCaseExecuteEngine
|
||||||
|
import NoseTestExecuteEngine
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import os
|
import os
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
|
|
||||||
parser.add_option("-c", "--config", action="store", default="./datacenterCfg", dest="config", help="the path where the json config file generated, by default is ./datacenterCfg")
|
parser.add_option("-c", "--config", action="store", default="./datacenterCfg", dest="config", help="the path where the json config file generated, by default is ./datacenterCfg")
|
||||||
parser.add_option("-d", "--directory", dest="testCaseFolder", help="the test case directory")
|
parser.add_option("-d", "--directory", dest="testCaseFolder", help="the test case directory")
|
||||||
parser.add_option("-r", "--result", dest="result", help="test result log file")
|
parser.add_option("-r", "--result", dest="result", help="test result log file")
|
||||||
parser.add_option("-t", dest="testcaselog", help="test case log file")
|
parser.add_option("-t", "--client", dest="testcaselog", help="test case log file")
|
||||||
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("-n", "--nose", dest="nose", action="store_true", help="run tests using nose")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
if options.testCaseFolder is None:
|
|
||||||
parser.print_usage()
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
testResultLogFile = None
|
testResultLogFile = None
|
||||||
if options.result is not None:
|
if options.result is not None:
|
||||||
testResultLogFile = options.result
|
testResultLogFile = options.result
|
||||||
@ -40,5 +41,23 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
deploy.deploy()
|
deploy.deploy()
|
||||||
|
|
||||||
testcaseEngine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, options.testCaseFolder, testCaseLogFile, testResultLogFile)
|
if options.testCaseFolder is None:
|
||||||
testcaseEngine.run()
|
if options.module is None:
|
||||||
|
parser.print_usage()
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
if options.nose:
|
||||||
|
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
||||||
|
engine.runTestsFromFile(options.module)
|
||||||
|
else:
|
||||||
|
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
||||||
|
engine.loadTestsFromFile(options.module)
|
||||||
|
engine.run()
|
||||||
|
else:
|
||||||
|
if options.nose:
|
||||||
|
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, clientLog=testCaseLogFile, resultLog=testResultLogFile, workingdir=options.testCaseFolder)
|
||||||
|
engine.runTests()
|
||||||
|
else:
|
||||||
|
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
|
||||||
|
engine.loadTestsFromDir(options.testCaseFolder)
|
||||||
|
engine.run()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user