mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
docs: add testcase fixture example to update teststep headers
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import uuid
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -37,14 +38,23 @@ def testcase_fixture(request):
|
|||||||
|
|
||||||
logger.debug(f"setup testcase fixture: {config.name} - {request.module.__name__}")
|
logger.debug(f"setup testcase fixture: {config.name} - {request.module.__name__}")
|
||||||
|
|
||||||
# prefix = f"HRUN-{uuid.uuid4()}"
|
def update_request_headers(steps, index):
|
||||||
# for index, teststep in enumerate(teststeps):
|
for teststep in steps:
|
||||||
# # you can update testcase teststep here
|
if teststep.request:
|
||||||
# teststep.request.headers["HRUN-Request-ID"] = f"{prefix}-{index}"
|
index += 1
|
||||||
|
teststep.request.headers["X-Request-ID"] = f"{prefix}-{index}"
|
||||||
|
elif teststep.testcase and hasattr(teststep.testcase, "teststeps"):
|
||||||
|
update_request_headers(teststep.testcase.teststeps, index)
|
||||||
|
|
||||||
|
# you can update testcase teststep like this
|
||||||
|
prefix = f"HRUN-{uuid.uuid4()}"
|
||||||
|
update_request_headers(teststeps, 0)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
logger.debug(f"teardown testcase fixture: {config.name} - {request.module.__name__}")
|
logger.debug(
|
||||||
|
f"teardown testcase fixture: {config.name} - {request.module.__name__}"
|
||||||
|
)
|
||||||
|
|
||||||
summary = request.instance.get_summary()
|
summary = request.instance.get_summary()
|
||||||
logger.debug(f"testcase result summary: {summary}")
|
logger.debug(f"testcase result summary: {summary}")
|
||||||
|
|||||||
@@ -43,6 +43,6 @@ class TestCli(unittest.TestCase):
|
|||||||
pytest.main(
|
pytest.main(
|
||||||
[
|
[
|
||||||
"-s",
|
"-s",
|
||||||
"examples/postman_echo/request_methods/request_with_variables_test.py",
|
"examples/postman_echo/request_methods/request_with_testcase_reference_test.py",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user