docs: add testcase fixture example to update teststep headers

This commit is contained in:
debugtalk
2020-05-27 10:57:53 +08:00
parent 2d76db0568
commit e278d67886
2 changed files with 16 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
import uuid
from typing import List
import pytest
@@ -37,14 +38,23 @@ def testcase_fixture(request):
logger.debug(f"setup testcase fixture: {config.name} - {request.module.__name__}")
# prefix = f"HRUN-{uuid.uuid4()}"
# for index, teststep in enumerate(teststeps):
# # you can update testcase teststep here
# teststep.request.headers["HRUN-Request-ID"] = f"{prefix}-{index}"
def update_request_headers(steps, index):
for teststep in steps:
if teststep.request:
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
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()
logger.debug(f"testcase result summary: {summary}")

View File

@@ -43,6 +43,6 @@ class TestCli(unittest.TestCase):
pytest.main(
[
"-s",
"examples/postman_echo/request_methods/request_with_variables_test.py",
"examples/postman_echo/request_methods/request_with_testcase_reference_test.py",
]
)