fix locust in testsuite

This commit is contained in:
debugtalk
2018-12-21 20:48:55 +08:00
parent 3423f5c945
commit 4090755826
4 changed files with 48 additions and 12 deletions

View File

@@ -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,

View File

@@ -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)

View 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

View File

@@ -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"])