mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-11 10:49:43 +08:00
fix: compatibility
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Dict, Text, NoReturn
|
from typing import List, Dict, Text, NoReturn, Union
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import allure
|
import allure
|
||||||
@@ -20,7 +20,7 @@ from httprunner.ext.uploader import prepare_upload_step
|
|||||||
from httprunner.loader import load_project_meta, load_testcase_file
|
from httprunner.loader import load_project_meta, load_testcase_file
|
||||||
from httprunner.parser import build_url, parse_data, parse_variables_mapping
|
from httprunner.parser import build_url, parse_data, parse_variables_mapping
|
||||||
from httprunner.response import ResponseObject
|
from httprunner.response import ResponseObject
|
||||||
from httprunner.testcase import Config, Step
|
from httprunner.testcase import Config, StepValidation
|
||||||
from httprunner.schema import (
|
from httprunner.schema import (
|
||||||
TConfig,
|
TConfig,
|
||||||
TStep,
|
TStep,
|
||||||
@@ -35,8 +35,8 @@ from httprunner.schema import (
|
|||||||
|
|
||||||
|
|
||||||
class HttpRunner(object):
|
class HttpRunner(object):
|
||||||
config: Config
|
config: Union[TConfig, Config]
|
||||||
teststeps: List[Step]
|
teststeps: List[Union[TStep, StepValidation]]
|
||||||
|
|
||||||
success: bool = True # indicate testcase execution result
|
success: bool = True # indicate testcase execution result
|
||||||
__config: TConfig
|
__config: TConfig
|
||||||
@@ -52,6 +52,23 @@ class HttpRunner(object):
|
|||||||
# log
|
# log
|
||||||
__log_path: Text = ""
|
__log_path: Text = ""
|
||||||
|
|
||||||
|
def __init_tests__(self) -> NoReturn:
|
||||||
|
if isinstance(self.config, TConfig):
|
||||||
|
self.__config = self.config
|
||||||
|
elif isinstance(self.config, Config):
|
||||||
|
self.__config = self.config.perform()
|
||||||
|
else:
|
||||||
|
raise exceptions.TestCaseFormatError(f"config type error: {self.config}")
|
||||||
|
|
||||||
|
self.__teststeps = []
|
||||||
|
for step in self.teststeps:
|
||||||
|
if isinstance(step, TStep):
|
||||||
|
self.__teststeps.append(step)
|
||||||
|
elif isinstance(step, StepValidation):
|
||||||
|
self.__teststeps.append(step.perform())
|
||||||
|
else:
|
||||||
|
raise exceptions.TestCaseFormatError(f"step type error: {step}")
|
||||||
|
|
||||||
def with_project_meta(self, project_meta: ProjectMeta) -> "HttpRunner":
|
def with_project_meta(self, project_meta: ProjectMeta) -> "HttpRunner":
|
||||||
self.__project_meta = project_meta
|
self.__project_meta = project_meta
|
||||||
return self
|
return self
|
||||||
@@ -272,8 +289,7 @@ class HttpRunner(object):
|
|||||||
>>> TestCaseRequestWithFunctions().run()
|
>>> TestCaseRequestWithFunctions().run()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.__config = self.config.perform()
|
self.__init_tests__()
|
||||||
self.__teststeps = [step.perform() for step in self.teststeps]
|
|
||||||
testcase_obj = TestCase(config=self.__config, teststeps=self.__teststeps)
|
testcase_obj = TestCase(config=self.__config, teststeps=self.__teststeps)
|
||||||
return self.run_testcase(testcase_obj)
|
return self.run_testcase(testcase_obj)
|
||||||
|
|
||||||
@@ -314,8 +330,7 @@ class HttpRunner(object):
|
|||||||
|
|
||||||
def test_start(self) -> "HttpRunner":
|
def test_start(self) -> "HttpRunner":
|
||||||
"""main entrance, discovered by pytest"""
|
"""main entrance, discovered by pytest"""
|
||||||
self.__config = self.config.perform()
|
self.__init_tests__()
|
||||||
self.__teststeps = [step.perform() for step in self.teststeps]
|
|
||||||
self.__project_meta = self.__project_meta or load_project_meta(
|
self.__project_meta = self.__project_meta or load_project_meta(
|
||||||
self.__config.path
|
self.__config.path
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user