mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
feat: describe testcase in chain-call style, run testcase
This commit is contained in:
@@ -6,7 +6,7 @@ import sys
|
|||||||
|
|
||||||
sys.path.insert(0, os.getcwd())
|
sys.path.insert(0, os.getcwd())
|
||||||
|
|
||||||
from httprunner import HttpRunner, TConfig, TStep
|
from httprunner import HttpRunner, Config, Step
|
||||||
|
|
||||||
from examples.postman_echo.request_methods.request_with_functions_test import (
|
from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||||
TestCaseRequestWithFunctions as RequestWithFunctions,
|
TestCaseRequestWithFunctions as RequestWithFunctions,
|
||||||
@@ -14,24 +14,17 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
|||||||
|
|
||||||
|
|
||||||
class TestCaseRequestWithTestcaseReference(HttpRunner):
|
class TestCaseRequestWithTestcaseReference(HttpRunner):
|
||||||
config = TConfig(
|
config = (
|
||||||
**{
|
Config("request methods testcase: reference testcase")
|
||||||
"name": "request methods testcase: reference testcase",
|
.variables(foo1="session_bar1")
|
||||||
"variables": {"foo1": "session_bar1"},
|
.base_url("https://postman-echo.com")
|
||||||
"base_url": "https://postman-echo.com",
|
.verify(False)
|
||||||
"verify": False,
|
|
||||||
"path": "examples/postman_echo/request_methods/request_with_testcase_reference_test.py",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
teststeps = [
|
teststeps = [
|
||||||
TStep(
|
Step("request with functions")
|
||||||
**{
|
.with_variables(foo1="override_bar1")
|
||||||
"name": "request with functions",
|
.run_testcase(RequestWithFunctions),
|
||||||
"variables": {"foo1": "override_bar1"},
|
|
||||||
"testcase": RequestWithFunctions,
|
|
||||||
}
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ class TRequest(BaseModel):
|
|||||||
|
|
||||||
class TStep(BaseModel):
|
class TStep(BaseModel):
|
||||||
name: Name
|
name: Name
|
||||||
request: TRequest = None
|
request: Union[TRequest, None] = None
|
||||||
testcase: Union[Text, Callable] = ""
|
testcase: Union[Text, Callable, None] = None
|
||||||
variables: VariablesMapping = {}
|
variables: VariablesMapping = {}
|
||||||
setup_hooks: Hook = []
|
setup_hooks: Hook = []
|
||||||
teardown_hooks: Hook = []
|
teardown_hooks: Hook = []
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import inspect
|
import inspect
|
||||||
from typing import Text, Any, Dict
|
from typing import Text, Any, Dict, Callable
|
||||||
|
|
||||||
from httprunner.schema import (
|
from httprunner.schema import (
|
||||||
TConfig,
|
TConfig,
|
||||||
TStep,
|
TStep,
|
||||||
TRequest,
|
TRequest,
|
||||||
MethodEnum,
|
MethodEnum,
|
||||||
|
TestCase,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -128,18 +129,28 @@ class Request(object):
|
|||||||
|
|
||||||
class StepValidation(object):
|
class StepValidation(object):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, name: Text, variables: Dict, extractors: Dict, request: TRequest
|
self,
|
||||||
|
name: Text,
|
||||||
|
variables: Dict,
|
||||||
|
extractors: Dict,
|
||||||
|
request: TRequest = None,
|
||||||
|
testcase: Callable = None,
|
||||||
):
|
):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__variables = variables
|
self.__variables = variables
|
||||||
self.__extractors = extractors
|
self.__extractors = extractors
|
||||||
self.__request = request
|
self.__request: TRequest = request
|
||||||
|
self.__testcase: Callable = testcase
|
||||||
self.__validators = []
|
self.__validators = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def request(self) -> TRequest:
|
def request(self) -> TRequest:
|
||||||
return self.__request
|
return self.__request
|
||||||
|
|
||||||
|
@property
|
||||||
|
def testcase(self) -> TestCase:
|
||||||
|
return self.__testcase
|
||||||
|
|
||||||
def assert_equal(self, jmes_path: Text, expected_value: Any) -> "StepValidation":
|
def assert_equal(self, jmes_path: Text, expected_value: Any) -> "StepValidation":
|
||||||
self.__validators.append({"eq": [jmes_path, expected_value]})
|
self.__validators.append({"eq": [jmes_path, expected_value]})
|
||||||
return self
|
return self
|
||||||
@@ -161,6 +172,7 @@ class StepValidation(object):
|
|||||||
name=self.__name,
|
name=self.__name,
|
||||||
variables=self.__variables,
|
variables=self.__variables,
|
||||||
request=self.__request,
|
request=self.__request,
|
||||||
|
testcase=self.__testcase,
|
||||||
extract=self.__extractors,
|
extract=self.__extractors,
|
||||||
validate=self.__validators,
|
validate=self.__validators,
|
||||||
)
|
)
|
||||||
@@ -171,7 +183,6 @@ class Step(object):
|
|||||||
self.__name = name
|
self.__name = name
|
||||||
self.__variables = {}
|
self.__variables = {}
|
||||||
self.__extractors = {}
|
self.__extractors = {}
|
||||||
self.__request = None
|
|
||||||
|
|
||||||
def with_variables(self, **variables) -> "Step":
|
def with_variables(self, **variables) -> "Step":
|
||||||
self.__variables.update(variables)
|
self.__variables.update(variables)
|
||||||
@@ -182,7 +193,11 @@ class Step(object):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def run_request(self, req_obj: RequestWithOptionalArgs) -> "StepValidation":
|
def run_request(self, req_obj: RequestWithOptionalArgs) -> "StepValidation":
|
||||||
self.__request = req_obj.perform()
|
|
||||||
return StepValidation(
|
return StepValidation(
|
||||||
self.__name, self.__variables, self.__extractors, self.__request
|
self.__name, self.__variables, self.__extractors, request=req_obj.perform()
|
||||||
|
)
|
||||||
|
|
||||||
|
def run_testcase(self, testcase: Callable) -> "StepValidation":
|
||||||
|
return StepValidation(
|
||||||
|
self.__name, self.__variables, self.__extractors, testcase=testcase
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user