mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: make testcase with weight
This commit is contained in:
@@ -6,6 +6,7 @@ testcases:
|
||||
-
|
||||
name: request with functions
|
||||
testcase: request_methods/request_with_functions.yml
|
||||
weight: 2
|
||||
variables:
|
||||
foo1: testcase_ref_bar11
|
||||
expect_foo1: testcase_ref_bar11
|
||||
@@ -13,6 +14,7 @@ testcases:
|
||||
-
|
||||
name: request with referenced testcase
|
||||
testcase: request_methods/request_with_testcase_reference.yml
|
||||
weight: 3
|
||||
variables:
|
||||
foo1: testcase_ref_bar12
|
||||
expect_foo1: testcase_ref_bar12
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
@@ -18,6 +18,7 @@ class TestCaseRequestWithFunctions(HttpRunner):
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
.export(*["foo3"])
|
||||
.locust_weight(2)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
|
||||
|
||||
import os
|
||||
@@ -26,6 +26,7 @@ class TestCaseRequestWithTestcaseReference(HttpRunner):
|
||||
)
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
.locust_weight(3)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/hardcode.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -7,6 +7,7 @@ config:
|
||||
expect_foo2: config_bar2
|
||||
base_url: "https://postman-echo.com"
|
||||
verify: False
|
||||
weight: 2
|
||||
export: ["foo3"]
|
||||
|
||||
teststeps:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
@@ -18,6 +18,7 @@ class TestCaseRequestWithFunctions(HttpRunner):
|
||||
.base_url("https://postman-echo.com")
|
||||
.verify(False)
|
||||
.export(*["foo3"])
|
||||
.locust_weight(2)
|
||||
)
|
||||
|
||||
teststeps = [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
|
||||
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/request_with_variables.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/validate_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTE: Generated By HttpRunner v3.0.13
|
||||
# NOTE: Generated By HttpRunner v3.1.0
|
||||
# FROM: examples/postman_echo/request_methods/validate_with_variables.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
__version__ = "3.1.0"
|
||||
__description__ = "One-stop solution for HTTP(S) testing."
|
||||
|
||||
from httprunner.ext.locust import main_locusts # import firstly for monkey patch if needed
|
||||
# import firstly for monkey patch if needed
|
||||
from httprunner.ext.locust import main_locusts
|
||||
from httprunner.runner import HttpRunner
|
||||
from httprunner.testcase import Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ def is_httprunner_testcase(item):
|
||||
""" check if a variable is a HttpRunner testcase class
|
||||
"""
|
||||
from httprunner import HttpRunner
|
||||
|
||||
# TODO: skip referenced testcase
|
||||
return bool(
|
||||
inspect.isclass(item)
|
||||
@@ -89,6 +90,7 @@ def main_locusts():
|
||||
sys.exit(1)
|
||||
|
||||
from httprunner.make import main_make
|
||||
|
||||
global pytest_files
|
||||
testcase_file_path = sys.argv[testcase_index]
|
||||
pytest_files = main_make([testcase_file_path])
|
||||
|
||||
@@ -12,8 +12,7 @@ class HttpRunnerUser(HttpUser):
|
||||
def on_start(self):
|
||||
locust_tests = prepare_locust_tests()
|
||||
self.testcase_runners = [
|
||||
testcase().with_session(self.client)
|
||||
for testcase in locust_tests
|
||||
testcase().with_session(self.client) for testcase in locust_tests
|
||||
]
|
||||
|
||||
@task
|
||||
|
||||
@@ -184,6 +184,9 @@ def make_config_chain_style(config: Dict) -> Text:
|
||||
if "export" in config:
|
||||
config_chain_style += f'.export(*{config["export"]})'
|
||||
|
||||
if "weight" in config:
|
||||
config_chain_style += f'.locust_weight({config["weight"]})'
|
||||
|
||||
return config_chain_style
|
||||
|
||||
|
||||
@@ -442,6 +445,10 @@ def make_testsuite(testsuite: Dict) -> NoReturn:
|
||||
)
|
||||
testcase_dict["config"]["variables"].update(testcase_variables)
|
||||
|
||||
# override weight
|
||||
weight = testcase.get("weight", 1)
|
||||
testcase_dict["config"]["weight"] = weight
|
||||
|
||||
# make testcase
|
||||
testcase_pytest_path = make_testcase(testcase_dict, testsuite_dir)
|
||||
pytest_files_run_set.add(testcase_pytest_path)
|
||||
|
||||
Reference in New Issue
Block a user