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