mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
feat: add default header for each testcase #721
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 3.0.5 (2020-05-21)
|
## 3.0.5 (2020-05-21)
|
||||||
|
|
||||||
|
**Added**
|
||||||
|
|
||||||
|
- feat: add default header `HRUN-Request-ID` for each testcase #721
|
||||||
|
|
||||||
**Fixed**
|
**Fixed**
|
||||||
|
|
||||||
- fix: ensure referenced testcase share the same session
|
- fix: ensure referenced testcase share the same session
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
__version__ = "3.0.4"
|
__version__ = "3.0.5"
|
||||||
__description__ = "One-stop solution for HTTP(S) testing."
|
__description__ = "One-stop solution for HTTP(S) testing."
|
||||||
|
|
||||||
from httprunner.runner import HttpRunner
|
from httprunner.runner import HttpRunner
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Dict, Text
|
from typing import List, Dict, Text
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ class HttpRunner(object):
|
|||||||
|
|
||||||
success: bool = True # indicate testcase execution result
|
success: bool = True # indicate testcase execution result
|
||||||
__project_meta: ProjectMeta = None
|
__project_meta: ProjectMeta = None
|
||||||
|
__hrun_request_id: Text = None
|
||||||
__step_datas: List[StepData] = None
|
__step_datas: List[StepData] = None
|
||||||
__session: HttpSession = None
|
__session: HttpSession = None
|
||||||
__session_variables: VariablesMapping = {}
|
__session_variables: VariablesMapping = {}
|
||||||
@@ -45,6 +47,10 @@ class HttpRunner(object):
|
|||||||
self.__session = session
|
self.__session = session
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def with_request_id(self, hrun_request_id: Text) -> "HttpRunner":
|
||||||
|
self.__hrun_request_id = hrun_request_id
|
||||||
|
return self
|
||||||
|
|
||||||
def with_variables(self, variables: VariablesMapping) -> "HttpRunner":
|
def with_variables(self, variables: VariablesMapping) -> "HttpRunner":
|
||||||
self.__session_variables = variables
|
self.__session_variables = variables
|
||||||
return self
|
return self
|
||||||
@@ -60,6 +66,10 @@ class HttpRunner(object):
|
|||||||
parsed_request_dict = parse_data(
|
parsed_request_dict = parse_data(
|
||||||
request_dict, step.variables, self.__project_meta.functions
|
request_dict, step.variables, self.__project_meta.functions
|
||||||
)
|
)
|
||||||
|
parsed_request_dict["headers"].setdefault(
|
||||||
|
"HRUN-Request-ID",
|
||||||
|
f"{self.__hrun_request_id}-{str(int(time.time() * 1000))[-6:]}",
|
||||||
|
)
|
||||||
|
|
||||||
# prepare arguments
|
# prepare arguments
|
||||||
method = parsed_request_dict.pop("method")
|
method = parsed_request_dict.pop("method")
|
||||||
@@ -131,6 +141,7 @@ class HttpRunner(object):
|
|||||||
case_result = (
|
case_result = (
|
||||||
HttpRunner()
|
HttpRunner()
|
||||||
.with_session(self.__session)
|
.with_session(self.__session)
|
||||||
|
.with_request_id(self.__hrun_request_id)
|
||||||
.with_variables(step_variables)
|
.with_variables(step_variables)
|
||||||
.run_path(ref_testcase_path)
|
.run_path(ref_testcase_path)
|
||||||
)
|
)
|
||||||
@@ -183,6 +194,7 @@ class HttpRunner(object):
|
|||||||
parse_config(self.config)
|
parse_config(self.config)
|
||||||
self.__start_at = time.time()
|
self.__start_at = time.time()
|
||||||
self.__step_datas: List[StepData] = []
|
self.__step_datas: List[StepData] = []
|
||||||
|
self.__hrun_request_id = self.__hrun_request_id or f"HRUN-{uuid.uuid4()}"
|
||||||
self.__session = self.__session or HttpSession()
|
self.__session = self.__session or HttpSession()
|
||||||
self.__session_variables = {}
|
self.__session_variables = {}
|
||||||
for step in self.teststeps:
|
for step in self.teststeps:
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "httprunner"
|
name = "httprunner"
|
||||||
version = "3.0.4"
|
version = "3.0.5"
|
||||||
description = "One-stop solution for HTTP(S) testing."
|
description = "One-stop solution for HTTP(S) testing."
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|||||||
Reference in New Issue
Block a user