mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
update prepare_locust_tests
This commit is contained in:
+4
-18
@@ -241,7 +241,7 @@ def prepare_locust_tests(path):
|
|||||||
|
|
||||||
{
|
{
|
||||||
"functions": {},
|
"functions": {},
|
||||||
"teststeps": []
|
"tests": []
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -253,23 +253,9 @@ def prepare_locust_tests(path):
|
|||||||
tests = []
|
tests = []
|
||||||
|
|
||||||
for testcase in parsed_tests_mapping["testcases"]:
|
for testcase in parsed_tests_mapping["testcases"]:
|
||||||
testcase_weight = testcase.get("config", {}).get("weight", 1)
|
testcase_weight = testcase.get("config", {}).pop("weight", 1)
|
||||||
items = testcase.get("teststeps", [])
|
for _ in range(testcase_weight):
|
||||||
|
tests.append(testcase)
|
||||||
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 {
|
return {
|
||||||
"functions": functions,
|
"functions": functions,
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
- config:
|
|
||||||
name: basic test with httpbin
|
|
||||||
base_url: https://httpbin.org/
|
|
||||||
|
|
||||||
- test:
|
|
||||||
name: index
|
|
||||||
weight: 5
|
|
||||||
request:
|
|
||||||
url: /
|
|
||||||
method: GET
|
|
||||||
validate:
|
|
||||||
- eq: ["status_code", 200]
|
|
||||||
- contains: [content, "HTTP Request & Response Service"]
|
|
||||||
|
|
||||||
- test:
|
|
||||||
name: headers
|
|
||||||
weight: 3
|
|
||||||
request:
|
|
||||||
url: /headers
|
|
||||||
method: GET
|
|
||||||
validate:
|
|
||||||
- eq: ["status_code", 200]
|
|
||||||
- eq: [content.headers.Host, "httpbin.org"]
|
|
||||||
|
|
||||||
- test:
|
|
||||||
name: user-agent
|
|
||||||
weight: 2
|
|
||||||
request:
|
|
||||||
url: /user-agent
|
|
||||||
method: GET
|
|
||||||
validate:
|
|
||||||
- eq: ["status_code", 200]
|
|
||||||
- startswith: [content.user-agent, "python-requests"]
|
|
||||||
+4
-13
@@ -610,18 +610,9 @@ class TestLocust(unittest.TestCase):
|
|||||||
|
|
||||||
def test_prepare_locust_tests(self):
|
def test_prepare_locust_tests(self):
|
||||||
path = os.path.join(
|
path = os.path.join(
|
||||||
os.getcwd(), 'tests/locust_tests/demo_simple_locust.yml')
|
os.getcwd(), 'tests/locust_tests/demo_locusts.yml')
|
||||||
locust_tests = prepare_locust_tests(path)
|
locust_tests = prepare_locust_tests(path)
|
||||||
self.assertIn("gen_md5", locust_tests["functions"])
|
self.assertIn("gen_md5", locust_tests["functions"])
|
||||||
self.assertEqual(len(locust_tests["tests"]), 10)
|
self.assertEqual(len(locust_tests["tests"]), 2 + 3)
|
||||||
self.assertEqual(locust_tests["tests"][0]["name"], "index")
|
self.assertIn("create user 1000 and check result.", locust_tests["tests"][0]["config"]["name"])
|
||||||
self.assertEqual(locust_tests["tests"][9]["name"], "user-agent")
|
self.assertIn("create user 1001 and check result.", locust_tests["tests"][4]["config"]["name"])
|
||||||
|
|
||||||
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"])
|
|
||||||
|
|||||||
@@ -7,12 +7,10 @@ config:
|
|||||||
testcases:
|
testcases:
|
||||||
create user 1000 and check result.:
|
create user 1000 and check result.:
|
||||||
testcase: testcases/create_and_check.yml
|
testcase: testcases/create_and_check.yml
|
||||||
weight: 2
|
|
||||||
variables:
|
variables:
|
||||||
uid: 1000
|
uid: 1000
|
||||||
|
|
||||||
create user 1001 and check result.:
|
create user 1001 and check result.:
|
||||||
testcase: testcases/create_and_check.yml
|
testcase: testcases/create_and_check.yml
|
||||||
weight: 23423
|
|
||||||
variables:
|
variables:
|
||||||
uid: 1001
|
uid: 1001
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ config:
|
|||||||
testcases:
|
testcases:
|
||||||
create user $uid and check result for $device_sn.:
|
create user $uid and check result for $device_sn.:
|
||||||
testcase: testcases/create_and_check.yml
|
testcase: testcases/create_and_check.yml
|
||||||
weight: 2
|
|
||||||
variables:
|
variables:
|
||||||
uid: 1000
|
uid: 1000
|
||||||
device_sn: TESTSUITE_XXX
|
device_sn: TESTSUITE_XXX
|
||||||
|
|||||||
Reference in New Issue
Block a user