mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix locust in testsuite
This commit is contained in:
@@ -244,21 +244,27 @@ def prepare_locust_tests(path):
|
||||
parsed_tests_mapping = parser.parse_tests(tests_mapping)
|
||||
|
||||
functions = parsed_tests_mapping.get("project_mapping", {}).get("functions", {})
|
||||
testcase = parsed_tests_mapping["testcases"][0]
|
||||
items = testcase.get("teststeps", [])
|
||||
|
||||
tests = []
|
||||
for item in items:
|
||||
if "config" in item:
|
||||
# embeded testcase
|
||||
weight = item["config"].get("weight", 1)
|
||||
else:
|
||||
# API test
|
||||
weight = item.get("weight", 1)
|
||||
|
||||
# implement weight for tests
|
||||
for _ in range(weight):
|
||||
tests.append(item)
|
||||
for testcase in parsed_tests_mapping["testcases"]:
|
||||
testcase_weight = testcase.get("config", {}).get("weight", 1)
|
||||
items = testcase.get("teststeps", [])
|
||||
|
||||
testcase_tests = []
|
||||
for item in items:
|
||||
if "config" in item:
|
||||
# embeded testcase
|
||||
weight = item["config"].get("weight", 1)
|
||||
else:
|
||||
# API test
|
||||
weight = item.get("weight", 1)
|
||||
|
||||
# implement weight for tests
|
||||
for _ in range(weight):
|
||||
testcase_tests.append(item)
|
||||
|
||||
tests.extend(testcase_tests * testcase_weight)
|
||||
|
||||
return {
|
||||
"functions": functions,
|
||||
|
||||
@@ -942,6 +942,9 @@ def __get_parsed_testsuite_testcases(testcases, testsuite_config, project_mappin
|
||||
parsed_testcase["path"] = testcase["testcase"]
|
||||
parsed_testcase["config"]["name"] = testcase_name
|
||||
|
||||
if "weight" in testcase:
|
||||
parsed_testcase["config"]["weight"] = testcase["weight"]
|
||||
|
||||
# base_url priority: testcase config > testsuite config
|
||||
parsed_testcase["config"].setdefault("base_url", testsuite_base_url)
|
||||
|
||||
|
||||
18
tests/locust_tests/demo_locust_with_layer.yml
Normal file
18
tests/locust_tests/demo_locust_with_layer.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
config:
|
||||
name: create users with uid
|
||||
variables:
|
||||
- device_sn: ${gen_random_string(15)}
|
||||
base_url: "http://127.0.0.1:5000"
|
||||
|
||||
testcases:
|
||||
create user 1000 and check result.:
|
||||
testcase: testcases/create_and_check.yml
|
||||
weight: 2
|
||||
variables:
|
||||
uid: 1000
|
||||
|
||||
create user 1001 and check result.:
|
||||
testcase: testcases/create_and_check.yml
|
||||
weight: 3
|
||||
variables:
|
||||
uid: 1001
|
||||
@@ -598,3 +598,12 @@ class TestLocust(unittest.TestCase):
|
||||
self.assertEqual(len(locust_tests["tests"]), 10)
|
||||
self.assertEqual(locust_tests["tests"][0]["name"], "index")
|
||||
self.assertEqual(locust_tests["tests"][9]["name"], "user-agent")
|
||||
|
||||
def test_prepare_locust_tests_with_layer(self):
|
||||
path = os.path.join(
|
||||
os.getcwd(), 'tests/locust_tests/demo_locust_with_layer.yml')
|
||||
locust_tests = prepare_locust_tests(path)
|
||||
self.assertIn("gen_md5", locust_tests["functions"])
|
||||
self.assertEqual(len(locust_tests["tests"]), 4 * 2 + 4 * 3)
|
||||
self.assertIn("setup and reset all (override)", locust_tests["tests"][0]["config"]["name"])
|
||||
self.assertIn("check if user ", locust_tests["tests"][19]["name"])
|
||||
|
||||
Reference in New Issue
Block a user