mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-10 18:29:37 +08:00
feat: make testcase with weight
This commit is contained in:
@@ -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