mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 08:27:35 +08:00
relocate functions related to .env
This commit is contained in:
@@ -163,10 +163,11 @@ def load_dot_env_file(dot_env_path):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if not os.path.isfile(dot_env_path):
|
if not os.path.isfile(dot_env_path):
|
||||||
raise exceptions.FileNotFound(".env file path is not exist.")
|
return {}
|
||||||
|
|
||||||
logger.log_info("Loading environment variables from {}".format(dot_env_path))
|
logger.log_info("Loading environment variables from {}".format(dot_env_path))
|
||||||
env_variables_mapping = {}
|
env_variables_mapping = {}
|
||||||
|
|
||||||
with io.open(dot_env_path, 'r', encoding='utf-8') as fp:
|
with io.open(dot_env_path, 'r', encoding='utf-8') as fp:
|
||||||
for line in fp:
|
for line in fp:
|
||||||
# maxsplit=1
|
# maxsplit=1
|
||||||
@@ -889,11 +890,9 @@ def load_project_tests(test_path, dot_env_path=None):
|
|||||||
|
|
||||||
# load .env
|
# load .env
|
||||||
dot_env_path = dot_env_path or os.path.join(project_working_directory, ".env")
|
dot_env_path = dot_env_path or os.path.join(project_working_directory, ".env")
|
||||||
if os.path.isfile(dot_env_path):
|
|
||||||
project_mapping["env"] = load_dot_env_file(dot_env_path)
|
project_mapping["env"] = load_dot_env_file(dot_env_path)
|
||||||
else:
|
|
||||||
project_mapping["env"] = {}
|
|
||||||
|
|
||||||
|
# load api/testcases
|
||||||
project_mapping["def-api"] = load_api_folder(os.path.join(project_working_directory, "api"))
|
project_mapping["def-api"] = load_api_folder(os.path.join(project_working_directory, "api"))
|
||||||
# TODO: replace suite with testcases
|
# TODO: replace suite with testcases
|
||||||
project_mapping["def-testcase"] = load_test_folder(os.path.join(project_working_directory, "suite"))
|
project_mapping["def-testcase"] = load_test_folder(os.path.join(project_working_directory, "suite"))
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ class TestFileLoader(unittest.TestCase):
|
|||||||
dot_env_path = os.path.join(
|
dot_env_path = os.path.join(
|
||||||
os.getcwd(), "tests", "data",
|
os.getcwd(), "tests", "data",
|
||||||
)
|
)
|
||||||
with self.assertRaises(exceptions.FileNotFound):
|
env_variables_mapping = loader.load_dot_env_file(dot_env_path)
|
||||||
loader.load_dot_env_file(dot_env_path)
|
self.assertEqual(env_variables_mapping, {})
|
||||||
|
|
||||||
def test_locate_file(self):
|
def test_locate_file(self):
|
||||||
with self.assertRaises(exceptions.FileNotFound):
|
with self.assertRaises(exceptions.FileNotFound):
|
||||||
|
|||||||
Reference in New Issue
Block a user