mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 08:27:35 +08:00
feat: get testcase result summary
This commit is contained in:
+31
-5
@@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@@ -14,15 +16,15 @@ from httprunner.schema import (
|
|||||||
TStep,
|
TStep,
|
||||||
VariablesMapping,
|
VariablesMapping,
|
||||||
StepData,
|
StepData,
|
||||||
|
TestCaseSummary,
|
||||||
|
TestCaseTime,
|
||||||
|
TestCaseInOut,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HttpRunner(object):
|
class HttpRunner(object):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self, config: TConfig, teststeps: List[TStep], session: HttpSession = None,
|
||||||
config: TConfig,
|
|
||||||
teststeps: List[TStep],
|
|
||||||
session: HttpSession = None,
|
|
||||||
):
|
):
|
||||||
if not config.path:
|
if not config.path:
|
||||||
raise exceptions.ParamsError("config path missed!")
|
raise exceptions.ParamsError("config path missed!")
|
||||||
@@ -36,6 +38,8 @@ class HttpRunner(object):
|
|||||||
self.success: bool = True # indicate testcase execution result
|
self.success: bool = True # indicate testcase execution result
|
||||||
|
|
||||||
self.project_data = load_project_meta(self.config.path)
|
self.project_data = load_project_meta(self.config.path)
|
||||||
|
self.start_at = 0
|
||||||
|
self.duration = 0
|
||||||
|
|
||||||
def with_variables(self, **variables: VariablesMapping) -> "HttpRunner":
|
def with_variables(self, **variables: VariablesMapping) -> "HttpRunner":
|
||||||
self.config.variables.update(variables)
|
self.config.variables.update(variables)
|
||||||
@@ -99,7 +103,9 @@ class HttpRunner(object):
|
|||||||
# validate
|
# validate
|
||||||
validators = step.validators
|
validators = step.validators
|
||||||
try:
|
try:
|
||||||
resp_obj.validate(validators, variables_mapping, self.project_data.functions)
|
resp_obj.validate(
|
||||||
|
validators, variables_mapping, self.project_data.functions
|
||||||
|
)
|
||||||
self.session.data.success = True
|
self.session.data.success = True
|
||||||
except ValidationFailure:
|
except ValidationFailure:
|
||||||
self.session.data.success = False
|
self.session.data.success = False
|
||||||
@@ -153,6 +159,7 @@ class HttpRunner(object):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""main entrance"""
|
"""main entrance"""
|
||||||
|
self.start_at = time.time()
|
||||||
self.step_datas.clear()
|
self.step_datas.clear()
|
||||||
self.session_variables.clear()
|
self.session_variables.clear()
|
||||||
for step in self.teststeps:
|
for step in self.teststeps:
|
||||||
@@ -169,6 +176,7 @@ class HttpRunner(object):
|
|||||||
# save extracted variables to session variables
|
# save extracted variables to session variables
|
||||||
self.session_variables.update(extract_mapping)
|
self.session_variables.update(extract_mapping)
|
||||||
|
|
||||||
|
self.duration = time.time() - self.start_at
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_export_variables(self):
|
def get_export_variables(self):
|
||||||
@@ -182,3 +190,21 @@ class HttpRunner(object):
|
|||||||
export_vars_mapping[var_name] = self.session_variables[var_name]
|
export_vars_mapping[var_name] = self.session_variables[var_name]
|
||||||
|
|
||||||
return export_vars_mapping
|
return export_vars_mapping
|
||||||
|
|
||||||
|
def get_summary(self) -> TestCaseSummary:
|
||||||
|
"""get testcase result summary"""
|
||||||
|
start_at_timestamp = self.start_at
|
||||||
|
start_at_iso_format = datetime.utcfromtimestamp(start_at_timestamp).isoformat()
|
||||||
|
return TestCaseSummary(
|
||||||
|
success=self.success,
|
||||||
|
time=TestCaseTime(
|
||||||
|
start_at=self.start_at,
|
||||||
|
start_at_iso_format=start_at_iso_format,
|
||||||
|
duration=self.duration,
|
||||||
|
),
|
||||||
|
name=self.config.name,
|
||||||
|
# status=result.status,
|
||||||
|
# attachment=result.attachment,
|
||||||
|
in_out=TestCaseInOut(vars=self.config.variables, out=self.config.export),
|
||||||
|
step_datas=self.step_datas,
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict, Text, Union, Callable
|
from typing import Dict, Text, Union, Callable
|
||||||
@@ -75,7 +76,7 @@ class ProjectMeta(BaseModel):
|
|||||||
debugtalk_py: Text = ""
|
debugtalk_py: Text = ""
|
||||||
functions: FunctionsMapping = {}
|
functions: FunctionsMapping = {}
|
||||||
env: Env = {}
|
env: Env = {}
|
||||||
PWD: Text = None
|
PWD: Text = os.getcwd()
|
||||||
test_path: Text = None # run with specified test path
|
test_path: Text = None # run with specified test path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user