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