Skip to content

Commit a0efa70

Browse files
Prasanna SanthanamPrasanna Santhanam
Prasanna Santhanam
authored and
Prasanna Santhanam
committed
support for running tests in a given script
1 parent dba1c01 commit a0efa70

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

Diff for: tools/marvin/marvin/TestCaseExecuteEngine.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ def testCaseLogger(message, logger=None):
2525
logger.debug(message)
2626

2727
class TestCaseExecuteEngine(object):
28-
def __init__(self, testclient, testCaseFolder, testcaseLogFile=None, testResultLogFile=None):
28+
def __init__(self, testclient, testcaseLogFile=None, testResultLogFile=None):
29+
"""
30+
Initialize the testcase execution engine, just the basics here
31+
@var testcaseLogFile: client log file
32+
@var testResultLogFile: summary report file
33+
"""
2934
self.testclient = testclient
30-
self.testCaseFolder = testCaseFolder
3135
self.logformat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
36+
self.loader = unittest.loader.TestLoader()
37+
self.suite = None
3238

3339
if testcaseLogFile is not None:
3440
self.logfile = testcaseLogFile
@@ -46,7 +52,18 @@ def __init__(self, testclient, testCaseFolder, testcaseLogFile=None, testResultL
4652
self.testResultLogFile = fp
4753
else:
4854
self.testResultLogFile = sys.stdout
49-
55+
56+
def loadTestsFromDir(self, testDirectory):
57+
""" Load the test suites from a package with multiple test files """
58+
self.suite = self.loader.discover(testDirectory)
59+
self.injectTestCase(self.suite)
60+
61+
def loadTestsFromFile(self, file_name):
62+
""" Load the tests from a single script/module """
63+
if os.path.isfile(file_name):
64+
self.suite = self.loader.discover(os.path.dirname(file_name), os.path.basename(file_name))
65+
self.injectTestCase(self.suite)
66+
5067
def injectTestCase(self, testSuites):
5168
for test in testSuites:
5269
if isinstance(test, unittest.BaseTestSuite):
@@ -67,8 +84,5 @@ def injectTestCase(self, testSuites):
6784
self.testclient.createNewApiClient(test.UserName, test.DomainName, test.AcctType)
6885

6986
def run(self):
70-
loader = unittest.loader.TestLoader()
71-
suite = loader.discover(self.testCaseFolder)
72-
self.injectTestCase(suite)
73-
74-
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(suite)
87+
if self.suite:
88+
unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(self.suite)

Diff for: tools/marvin/marvin/deployAndRun.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@
1212
# Automatically generated by addcopyright.py at 04/03/2012
1313
import deployDataCenter
1414
import TestCaseExecuteEngine
15+
import NoseTestExecuteEngine
1516
from optparse import OptionParser
1617
import os
18+
1719
if __name__ == "__main__":
1820
parser = OptionParser()
1921

2022
parser.add_option("-c", "--config", action="store", default="./datacenterCfg", dest="config", help="the path where the json config file generated, by default is ./datacenterCfg")
2123
parser.add_option("-d", "--directory", dest="testCaseFolder", help="the test case directory")
2224
parser.add_option("-r", "--result", dest="result", help="test result log file")
23-
parser.add_option("-t", dest="testcaselog", help="test case log file")
25+
parser.add_option("-t", "--client", dest="testcaselog", help="test case log file")
2426
parser.add_option("-l", "--load", dest="load", action="store_true", help="only load config, do not deploy, it will only run testcase")
27+
parser.add_option("-f", "--file", dest="module", help="run tests in the given file")
28+
parser.add_option("-n", "--nose", dest="nose", action="store_true", help="run tests using nose")
2529
(options, args) = parser.parse_args()
26-
if options.testCaseFolder is None:
27-
parser.print_usage()
28-
exit(1)
29-
30+
3031
testResultLogFile = None
3132
if options.result is not None:
3233
testResultLogFile = options.result
@@ -40,5 +41,23 @@
4041
else:
4142
deploy.deploy()
4243

43-
testcaseEngine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, options.testCaseFolder, testCaseLogFile, testResultLogFile)
44-
testcaseEngine.run()
44+
if options.testCaseFolder is None:
45+
if options.module is None:
46+
parser.print_usage()
47+
exit(1)
48+
else:
49+
if options.nose:
50+
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
51+
engine.runTestsFromFile(options.module)
52+
else:
53+
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
54+
engine.loadTestsFromFile(options.module)
55+
engine.run()
56+
else:
57+
if options.nose:
58+
engine = NoseTestExecuteEngine.NoseTestExecuteEngine(deploy.testClient, clientLog=testCaseLogFile, resultLog=testResultLogFile, workingdir=options.testCaseFolder)
59+
engine.runTests()
60+
else:
61+
engine = TestCaseExecuteEngine.TestCaseExecuteEngine(deploy.testClient, testCaseLogFile, testResultLogFile)
62+
engine.loadTestsFromDir(options.testCaseFolder)
63+
engine.run()

0 commit comments

Comments
 (0)