mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 15:01:22 +08:00
feat: each testcase has an unique id in uuid4 format
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
**Added**
|
**Added**
|
||||||
|
|
||||||
|
- feat: each testcase has an unique id in uuid4 format
|
||||||
- feat: add default header `HRUN-Request-ID` for each testcase #721
|
- feat: add default header `HRUN-Request-ID` for each testcase #721
|
||||||
- feat: builtin allure report
|
- feat: builtin allure report
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,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
|
__case_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 = {}
|
||||||
@@ -48,8 +48,8 @@ class HttpRunner(object):
|
|||||||
self.__session = session
|
self.__session = session
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def with_request_id(self, hrun_request_id: Text) -> "HttpRunner":
|
def with_case_id(self, case_id: Text) -> "HttpRunner":
|
||||||
self.__hrun_request_id = hrun_request_id
|
self.__case_id = case_id
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def with_variables(self, variables: VariablesMapping) -> "HttpRunner":
|
def with_variables(self, variables: VariablesMapping) -> "HttpRunner":
|
||||||
@@ -69,7 +69,7 @@ class HttpRunner(object):
|
|||||||
)
|
)
|
||||||
parsed_request_dict["headers"].setdefault(
|
parsed_request_dict["headers"].setdefault(
|
||||||
"HRUN-Request-ID",
|
"HRUN-Request-ID",
|
||||||
f"{self.__hrun_request_id}-{str(int(time.time() * 1000))[-6:]}",
|
f"HRUN-{self.__case_id}-{str(int(time.time() * 1000))[-6:]}",
|
||||||
)
|
)
|
||||||
|
|
||||||
# prepare arguments
|
# prepare arguments
|
||||||
@@ -142,7 +142,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_case_id(self.__case_id)
|
||||||
.with_variables(step_variables)
|
.with_variables(step_variables)
|
||||||
.run_path(ref_testcase_path)
|
.run_path(ref_testcase_path)
|
||||||
)
|
)
|
||||||
@@ -174,7 +174,9 @@ class HttpRunner(object):
|
|||||||
"""main entrance"""
|
"""main entrance"""
|
||||||
self.config = testcase.config
|
self.config = testcase.config
|
||||||
self.teststeps = testcase.teststeps
|
self.teststeps = testcase.teststeps
|
||||||
self.config.variables.update(self.__session_variables)
|
|
||||||
|
self.__case_id = self.__case_id or str(uuid.uuid4())
|
||||||
|
logger.info(f"Start to run testcase: {self.config.name}, TestCase ID: {self.__case_id}")
|
||||||
|
|
||||||
if self.config.path:
|
if self.config.path:
|
||||||
self.__project_meta = load_project_meta(self.config.path)
|
self.__project_meta = load_project_meta(self.config.path)
|
||||||
@@ -192,16 +194,16 @@ class HttpRunner(object):
|
|||||||
config.base_url, config.variables, self.__project_meta.functions
|
config.base_url, config.variables, self.__project_meta.functions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.config.variables.update(self.__session_variables)
|
||||||
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 = {}
|
||||||
|
|
||||||
# update allure report meta
|
# update allure report meta
|
||||||
allure.dynamic.title(self.config.name)
|
allure.dynamic.title(self.config.name)
|
||||||
allure.dynamic.description(f"Request ID Prefix: {self.__hrun_request_id}")
|
allure.dynamic.description(f"TestCase ID: {self.__case_id}")
|
||||||
|
|
||||||
for step in self.teststeps:
|
for step in self.teststeps:
|
||||||
# update with config variables
|
# update with config variables
|
||||||
|
|||||||
Reference in New Issue
Block a user