mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 15:31:23 +08:00
run_testsets: optimize testsets structure
This commit is contained in:
@@ -82,26 +82,30 @@ class TestRunner(object):
|
|||||||
"requires": [],
|
"requires": [],
|
||||||
"function_binds": {},
|
"function_binds": {},
|
||||||
"variable_binds": []
|
"variable_binds": []
|
||||||
}
|
},
|
||||||
|
"testcases": [
|
||||||
|
{
|
||||||
|
"variable_binds": {}, # override
|
||||||
|
"request": {},
|
||||||
|
"response": {}
|
||||||
|
},
|
||||||
|
testcase12
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"test": {
|
"config": {},
|
||||||
"variable_binds": {}, # override
|
"testcases": [testcase21, testcase22, testcase23]
|
||||||
"request": {},
|
},
|
||||||
"response": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
results = []
|
results = []
|
||||||
for item in testsets:
|
|
||||||
for key in item:
|
for testset in testsets:
|
||||||
if key == "config":
|
config_dict = testset.get("config", {})
|
||||||
config_dict = item[key]
|
self.pre_config(config_dict)
|
||||||
self.pre_config(config_dict)
|
testcases = testset.get("testcases", [])
|
||||||
elif key == "test":
|
for testcase in testcases:
|
||||||
testcase = item[key]
|
result = self.run_test(testcase)
|
||||||
result = self.run_test(testcase)
|
results.append(result)
|
||||||
results.append(result)
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|||||||
@@ -78,14 +78,14 @@ class TestRunner(ApiServerUnittest):
|
|||||||
|
|
||||||
def test_run_testcase_suite_json_success(self):
|
def test_run_testcase_suite_json_success(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.json')
|
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.json')
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testsets = utils.load_testcases_by_path(testcase_file_path)
|
||||||
result = self.test_runner.run_testsets(testcases)
|
results = self.test_runner.run_testsets(testsets)
|
||||||
self.assertEqual(len(result), 2)
|
self.assertEqual(len(results), 2)
|
||||||
self.assertEqual(result, [(True, {}), (True, {})])
|
self.assertEqual(results, [(True, {}), (True, {})])
|
||||||
|
|
||||||
def test_run_testcase_suite_yaml_success(self):
|
def test_run_testcase_suite_yaml_success(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
|
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testsets = utils.load_testcases_by_path(testcase_file_path)
|
||||||
result = self.test_runner.run_testsets(testcases)
|
results = self.test_runner.run_testsets(testsets)
|
||||||
self.assertEqual(len(result), 2)
|
self.assertEqual(len(results), 2)
|
||||||
self.assertEqual(result, [(True, {}), (True, {})])
|
self.assertEqual(results, [(True, {}), (True, {})])
|
||||||
|
|||||||
@@ -34,16 +34,17 @@ class TestRunnerV2(ApiServerUnittest):
|
|||||||
def test_run_testcase_auth_suite_yaml(self):
|
def test_run_testcase_auth_suite_yaml(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'test/data/simple_demo_auth_hardcode.yml')
|
os.getcwd(), 'test/data/simple_demo_auth_hardcode.yml')
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testsets = utils.load_testcases_by_path(testcase_file_path)
|
||||||
results = self.test_runner.run_testsets(testcases)
|
results = self.test_runner.run_testsets(testsets)
|
||||||
self.assertEqual(len(results), 2)
|
self.assertEqual(len(results), 2)
|
||||||
self.assertEqual(results, [(True, {}), (True, {})])
|
self.assertEqual(results, [(True, {}), (True, {})])
|
||||||
|
|
||||||
|
|
||||||
def test_run_testcase_auth_suite_json(self):
|
def test_run_testcase_auth_suite_json(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'test/data/simple_demo_auth_hardcode.json')
|
os.getcwd(), 'test/data/simple_demo_auth_hardcode.json')
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testsets = utils.load_testcases_by_path(testcase_file_path)
|
||||||
results = self.test_runner.run_testsets(testcases)
|
results = self.test_runner.run_testsets(testsets)
|
||||||
self.assertEqual(len(results), 2)
|
self.assertEqual(len(results), 2)
|
||||||
self.assertEqual(results, [(True, {}), (True, {})])
|
self.assertEqual(results, [(True, {}), (True, {})])
|
||||||
|
|
||||||
@@ -59,6 +60,7 @@ class TestRunnerV2(ApiServerUnittest):
|
|||||||
def test_run_testcase_template_sets_yaml(self):
|
def test_run_testcase_template_sets_yaml(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'test/data/demo_template_sets.yml')
|
os.getcwd(), 'test/data/demo_template_sets.yml')
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testsets = utils.load_testcases_by_path(testcase_file_path)
|
||||||
results = self.test_runner.run_testsets(testcases)
|
results = self.test_runner.run_testsets(testsets)
|
||||||
|
self.assertEqual(len(results), 2)
|
||||||
self.assertEqual(results, [(True, {}), (True, {})])
|
self.assertEqual(results, [(True, {}), (True, {})])
|
||||||
|
|||||||
Reference in New Issue
Block a user