mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-24 09:50:00 +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))
|
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.
|
""" create test suite with a testset, it may include one or several testcases.
|
||||||
each suite should initialize a separate Runner() with testset config.
|
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()
|
def _add_tests_to_suite(self, testcases):
|
||||||
config_dict = testset.get("config", {})
|
for testcase in testcases:
|
||||||
test_runner.init_config(config_dict, level="testset")
|
if utils.PYTHON_VERSION == 3:
|
||||||
testcases = testset.get("testcases", [])
|
ApiTestCase.runTest.__doc__ = testcase['name']
|
||||||
|
else:
|
||||||
|
ApiTestCase.runTest.__func__.__doc__ = testcase['name']
|
||||||
|
|
||||||
for testcase in testcases:
|
test = ApiTestCase(self.test_runner, testcase)
|
||||||
if utils.PYTHON_VERSION == 3:
|
self.addTest(test)
|
||||||
ApiTestCase.runTest.__doc__ = testcase['name']
|
|
||||||
else:
|
|
||||||
ApiTestCase.runTest.__func__.__doc__ = testcase['name']
|
|
||||||
|
|
||||||
test = ApiTestCase(test_runner, testcase)
|
def print_output(self):
|
||||||
suite.addTest(test)
|
output_variables_list = self.config_dict.get("output", [])
|
||||||
|
self.test_runner.generate_output(output_variables_list)
|
||||||
|
|
||||||
return suite
|
|
||||||
|
|
||||||
def create_task(testcase_path):
|
def create_task(testcase_path):
|
||||||
""" create test task suite with specified 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)
|
testsets = testcase.load_testcases_by_path(testcase_path)
|
||||||
|
|
||||||
for testset in testsets:
|
for testset in testsets:
|
||||||
suite = create_suite(testset)
|
suite = ApiTestSuite(testset)
|
||||||
task_suite.addTest(suite)
|
task_suite.addTest(suite)
|
||||||
|
|
||||||
return task_suite
|
return task_suite
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class TestTask(ApiServerUnittest):
|
|||||||
def test_create_suite(self):
|
def test_create_suite(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testsets = load_testcases_by_path(testcase_file_path)
|
||||||
suite = task.create_suite(testsets[0])
|
suite = task.ApiTestSuite(testsets[0])
|
||||||
self.assertEqual(suite.countTestCases(), 3)
|
self.assertEqual(suite.countTestCases(), 3)
|
||||||
for testcase in suite:
|
for testcase in suite:
|
||||||
self.assertIsInstance(testcase, task.ApiTestCase)
|
self.assertIsInstance(testcase, task.ApiTestCase)
|
||||||
|
|||||||
Reference in New Issue
Block a user