refactor: get config path with inspect stack

This commit is contained in:
debugtalk
2020-06-03 16:50:53 +08:00
parent 2b30a1337b
commit a465906626
2 changed files with 5 additions and 10 deletions
@@ -10,9 +10,6 @@ class TestCaseRequestWithFunctions(HttpRunner):
.variables(foo1="session_bar1") .variables(foo1="session_bar1")
.base_url("https://postman-echo.com") .base_url("https://postman-echo.com")
.verify(False) .verify(False)
.set_path(
"examples/postman_echo/request_methods/request_with_functions_test.py"
)
) )
teststeps = [ teststeps = [
+5 -7
View File
@@ -1,4 +1,5 @@
from typing import Text, Any, Dict import inspect
from typing import Text, Any
from httprunner.schema import ( from httprunner.schema import (
TConfig, TConfig,
@@ -14,7 +15,9 @@ class Config(object):
self.__variables = {} self.__variables = {}
self.__base_url = "" self.__base_url = ""
self.__verify = False self.__verify = False
self.__path = ""
caller_frame = inspect.stack()[1]
self.__path = caller_frame.filename
@property @property
def name(self): def name(self):
@@ -36,10 +39,6 @@ class Config(object):
self.__verify = verify self.__verify = verify
return self return self
def set_path(self, path: Text) -> "Config":
self.__path = path
return self
def perform(self) -> TConfig: def perform(self) -> TConfig:
return TConfig( return TConfig(
name=self.__name, name=self.__name,
@@ -171,4 +170,3 @@ class Step(object):
extract=self.__extract, extract=self.__extract,
validate=self.__validators, validate=self.__validators,
) )