From d957e2564f97a2897e78a127b567f77c98522515 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 31 Aug 2018 16:29:13 +0800 Subject: [PATCH] fix #368: failed to load .env data in debugtalk.py --- httprunner/loader.py | 12 ++++++++---- tests/debugtalk.py | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/httprunner/loader.py b/httprunner/loader.py index 69ffb362..75d8e535 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -892,19 +892,23 @@ def load_project_tests(test_path): load_builtin_module() debugtalk_path = locate_debugtalk_py(test_path) + # locate PWD with debugtalk.py path if debugtalk_path: # The folder contains debugtalk.py will be treated as PWD. # add PWD to sys.path project_working_directory = os.path.dirname(debugtalk_path) - - # load debugtalk.py - sys.path.insert(0, project_working_directory) - load_debugtalk_module() else: # debugtalk.py not found, use os.getcwd() as PWD. project_working_directory = os.getcwd() + # load .env load_dot_env_file() + + # load debugtalk.py + if debugtalk_path: + sys.path.insert(0, project_working_directory) + load_debugtalk_module() + load_api_folder(os.path.join(project_working_directory, "api")) # TODO: replace suite with testcases load_test_folder(os.path.join(project_working_directory, "suite")) diff --git a/tests/debugtalk.py b/tests/debugtalk.py index d232fe0e..b44239de 100644 --- a/tests/debugtalk.py +++ b/tests/debugtalk.py @@ -7,6 +7,8 @@ import time from tests.api_server import HTTPBIN_SERVER, SECRET_KEY, gen_md5, get_sign BASE_URL = "http://127.0.0.1:5000" +UserName = os.environ['UserName'] + demo_default_request = { "base_url": "$BASE_URL",