mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
make ApiTestSuite class to hold ApiTestCase
This commit is contained in:
@@ -1 +1 @@
|
||||
__version__ = '0.7.1'
|
||||
__version__ = '0.7.2'
|
||||
35
ate/task.py
35
ate/task.py
@@ -16,27 +16,32 @@ class ApiTestCase(unittest.TestCase):
|
||||
"""
|
||||
self.assertTrue(self.test_runner.run_test(self.testcase))
|
||||
|
||||
def create_suite(testset):
|
||||
class ApiTestSuite(unittest.TestSuite):
|
||||
""" create test suite with a testset, it may include one or several testcases.
|
||||
each suite should initialize a separate Runner() with testset config.
|
||||
"""
|
||||
suite = unittest.TestSuite()
|
||||
def __init__(self, testset):
|
||||
super(ApiTestSuite, self).__init__()
|
||||
self.test_runner = runner.Runner()
|
||||
self.config_dict = testset.get("config", {})
|
||||
self.test_runner.init_config(self.config_dict, level="testset")
|
||||
testcases = testset.get("testcases", [])
|
||||
self._add_tests_to_suite(testcases)
|
||||
|
||||
test_runner = runner.Runner()
|
||||
config_dict = testset.get("config", {})
|
||||
test_runner.init_config(config_dict, level="testset")
|
||||
testcases = testset.get("testcases", [])
|
||||
def _add_tests_to_suite(self, testcases):
|
||||
for testcase in testcases:
|
||||
if utils.PYTHON_VERSION == 3:
|
||||
ApiTestCase.runTest.__doc__ = testcase['name']
|
||||
else:
|
||||
ApiTestCase.runTest.__func__.__doc__ = testcase['name']
|
||||
|
||||
for testcase in testcases:
|
||||
if utils.PYTHON_VERSION == 3:
|
||||
ApiTestCase.runTest.__doc__ = testcase['name']
|
||||
else:
|
||||
ApiTestCase.runTest.__func__.__doc__ = testcase['name']
|
||||
test = ApiTestCase(self.test_runner, testcase)
|
||||
self.addTest(test)
|
||||
|
||||
test = ApiTestCase(test_runner, testcase)
|
||||
suite.addTest(test)
|
||||
def print_output(self):
|
||||
output_variables_list = self.config_dict.get("output", [])
|
||||
self.test_runner.generate_output(output_variables_list)
|
||||
|
||||
return suite
|
||||
|
||||
def create_task(testcase_path):
|
||||
""" create test task suite with specified testcase path.
|
||||
@@ -46,7 +51,7 @@ def create_task(testcase_path):
|
||||
testsets = testcase.load_testcases_by_path(testcase_path)
|
||||
|
||||
for testset in testsets:
|
||||
suite = create_suite(testset)
|
||||
suite = ApiTestSuite(testset)
|
||||
task_suite.addTest(suite)
|
||||
|
||||
return task_suite
|
||||
|
||||
@@ -18,7 +18,7 @@ class TestTask(ApiServerUnittest):
|
||||
def test_create_suite(self):
|
||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
||||
testsets = load_testcases_by_path(testcase_file_path)
|
||||
suite = task.create_suite(testsets[0])
|
||||
suite = task.ApiTestSuite(testsets[0])
|
||||
self.assertEqual(suite.countTestCases(), 3)
|
||||
for testcase in suite:
|
||||
self.assertIsInstance(testcase, task.ApiTestCase)
|
||||
|
||||
Reference in New Issue
Block a user