mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-10 18:29:37 +08:00
refactor: make step extensible to support implementing new protocols and test types for python version
This commit is contained in:
60
httprunner/config.py
Normal file
60
httprunner/config.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import inspect
|
||||
from typing import Text
|
||||
|
||||
from httprunner.models import TConfig
|
||||
|
||||
|
||||
class Config(object):
|
||||
def __init__(self, name: Text):
|
||||
self.__name = name
|
||||
self.__variables = {}
|
||||
self.__base_url = ""
|
||||
self.__verify = False
|
||||
self.__export = []
|
||||
self.__weight = 1
|
||||
|
||||
caller_frame = inspect.stack()[1]
|
||||
self.__path = caller_frame.filename
|
||||
|
||||
@property
|
||||
def name(self) -> Text:
|
||||
return self.__name
|
||||
|
||||
@property
|
||||
def path(self) -> Text:
|
||||
return self.__path
|
||||
|
||||
@property
|
||||
def weight(self) -> int:
|
||||
return self.__weight
|
||||
|
||||
def variables(self, **variables) -> "Config":
|
||||
self.__variables.update(variables)
|
||||
return self
|
||||
|
||||
def base_url(self, base_url: Text) -> "Config":
|
||||
self.__base_url = base_url
|
||||
return self
|
||||
|
||||
def verify(self, verify: bool) -> "Config":
|
||||
self.__verify = verify
|
||||
return self
|
||||
|
||||
def export(self, *export_var_name: Text) -> "Config":
|
||||
self.__export.extend(export_var_name)
|
||||
return self
|
||||
|
||||
def locust_weight(self, weight: int) -> "Config":
|
||||
self.__weight = weight
|
||||
return self
|
||||
|
||||
def struct(self) -> TConfig:
|
||||
return TConfig(
|
||||
name=self.__name,
|
||||
base_url=self.__base_url,
|
||||
verify=self.__verify,
|
||||
variables=self.__variables,
|
||||
export=list(set(self.__export)),
|
||||
path=self.__path,
|
||||
weight=self.__weight,
|
||||
)
|
||||
Reference in New Issue
Block a user