mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-25 09:33:43 +08:00
remove --dot-env-path argument
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,4 +12,3 @@ logs/%
|
||||
.coverage
|
||||
locustfile.py
|
||||
site/
|
||||
.env
|
||||
@@ -18,7 +18,6 @@ class HttpRunner(object):
|
||||
|
||||
resultclass (class): HtmlTestResult or TextTestResult
|
||||
failfast (bool): False/True, stop the test run on the first error or failure.
|
||||
dot_env_path (str): .env file path.
|
||||
http_client_session (instance): requests.Session(), or locust.client.Session() instance.
|
||||
|
||||
Attributes:
|
||||
@@ -46,10 +45,6 @@ class HttpRunner(object):
|
||||
"""
|
||||
loader.reset_loader()
|
||||
|
||||
# load .env
|
||||
dot_env_path = self.kwargs.pop("dot_env_path", None)
|
||||
loader.load_dot_env_file(dot_env_path)
|
||||
|
||||
# load api/testcase definition and debugtalk.py module
|
||||
project_folder_path = os.path.join(os.getcwd(), "tests") # TODO: remove tests
|
||||
loader.load_project_tests(project_folder_path)
|
||||
|
||||
@@ -39,9 +39,6 @@ def main_hrun():
|
||||
parser.add_argument(
|
||||
'--log-file',
|
||||
help="Write logs to specified file path.")
|
||||
parser.add_argument(
|
||||
'--dot-env-path',
|
||||
help="Specify .env file path, which is useful for keeping production credentials.")
|
||||
parser.add_argument(
|
||||
'--failfast', action='store_true', default=False,
|
||||
help="Stop the test run on the first error or failure.")
|
||||
@@ -78,7 +75,7 @@ def main_hrun():
|
||||
create_scaffold(project_path)
|
||||
exit(0)
|
||||
|
||||
runner = HttpRunner(failfast=args.failfast, dot_env_path=args.dot_env_path).run(args.testset_paths)
|
||||
runner = HttpRunner(failfast=args.failfast).run(args.testset_paths)
|
||||
|
||||
if not args.no_html_report:
|
||||
runner.gen_html_report(
|
||||
|
||||
@@ -22,6 +22,7 @@ project_mapping = {
|
||||
"""
|
||||
|
||||
testcases_cache_mapping = {}
|
||||
project_working_directory = os.getcwd()
|
||||
|
||||
|
||||
###############################################################################
|
||||
@@ -156,12 +157,8 @@ def load_folder_files(folder_path, recursive=True):
|
||||
return file_list
|
||||
|
||||
|
||||
def load_dot_env_file(path):
|
||||
""" load .env file
|
||||
|
||||
Args:
|
||||
path (str): .env file path.
|
||||
If path is None, it will find .env file in current working directory.
|
||||
def load_dot_env_file():
|
||||
""" load .env file, .env file should be located in project working directory.
|
||||
|
||||
Returns:
|
||||
dict: environment variables mapping
|
||||
@@ -173,18 +170,13 @@ def load_dot_env_file(path):
|
||||
}
|
||||
|
||||
Raises:
|
||||
exceptions.FileNotFound: If specified env file is not exist.
|
||||
exceptions.FileFormatError: If env file format is invalid.
|
||||
|
||||
"""
|
||||
if not path:
|
||||
path = os.path.join(os.getcwd(), ".env")
|
||||
if not os.path.isfile(path):
|
||||
logger.log_debug(".env file not exist: {}".format(path))
|
||||
return {}
|
||||
else:
|
||||
if not os.path.isfile(path):
|
||||
raise exceptions.FileNotFound("env file not exist: {}".format(path))
|
||||
path = os.path.join(project_working_directory, ".env")
|
||||
if not os.path.isfile(path):
|
||||
logger.log_debug(".env file not exist in : {}".format(project_working_directory))
|
||||
return {}
|
||||
|
||||
logger.log_info("Loading environment variables from {}".format(path))
|
||||
env_variables_mapping = {}
|
||||
@@ -910,6 +902,8 @@ def load_project_tests(folder_path):
|
||||
load_builtin_module()
|
||||
load_api_folder(os.path.join(folder_path, "api"))
|
||||
load_test_folder(os.path.join(folder_path, "suite"))
|
||||
# load .env
|
||||
load_dot_env_file()
|
||||
|
||||
|
||||
def load_testcases(path):
|
||||
|
||||
@@ -339,14 +339,6 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
self.assertIn("in", summary["details"][0]["in_out"])
|
||||
self.assertIn("out", summary["details"][0]["in_out"])
|
||||
|
||||
def test_loader(self):
|
||||
hrunner = HttpRunner(dot_env_path="tests/data/test.env")
|
||||
self.assertEqual(hrunner.project_mapping["env"]["PROJECT_KEY"], "ABCDEFGH")
|
||||
self.assertIn("debugtalk", hrunner.project_mapping)
|
||||
self.assertIn("setup_and_reset", hrunner.project_mapping["def-testcase"])
|
||||
self.assertIn("get_token", hrunner.project_mapping["def-api"])
|
||||
self.assertIn("setup_and_reset", hrunner.project_mapping["def-testcase"])
|
||||
|
||||
def test_load_tests(self):
|
||||
testcase_file_path = os.path.join(
|
||||
os.getcwd(), 'tests/data/demo_testcase.yml')
|
||||
|
||||
@@ -133,13 +133,18 @@ class TestFileLoader(unittest.TestCase):
|
||||
self.assertEqual([], files)
|
||||
|
||||
def test_load_dot_env_file(self):
|
||||
env_variables_mapping = loader.load_dot_env_file("tests/data/test.env")
|
||||
loader.project_working_directory = os.path.join(
|
||||
os.getcwd(), "tests",
|
||||
)
|
||||
env_variables_mapping = loader.load_dot_env_file()
|
||||
self.assertIn("PROJECT_KEY", env_variables_mapping)
|
||||
self.assertEqual(env_variables_mapping["UserName"], "debugtalk")
|
||||
|
||||
def test_load_env_path_not_exist(self):
|
||||
with self.assertRaises(exceptions.FileNotFound):
|
||||
loader.load_dot_env_file("not_exist.env")
|
||||
loader.project_working_directory = os.path.join(
|
||||
os.getcwd(), "tests", "data",
|
||||
)
|
||||
loader.load_dot_env_file()
|
||||
|
||||
def test_locate_file(self):
|
||||
with self.assertRaises(exceptions.FileNotFound):
|
||||
@@ -166,7 +171,7 @@ class TestFileLoader(unittest.TestCase):
|
||||
"tests/debugtalk.py"
|
||||
)
|
||||
self.assertEqual(
|
||||
loader.locate_file("tests/data/test.env", "debugtalk.py"),
|
||||
loader.locate_file("tests/data/demo_testcase.yml", "debugtalk.py"),
|
||||
"tests/debugtalk.py"
|
||||
)
|
||||
|
||||
@@ -478,10 +483,11 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_load_project_tests(self):
|
||||
project_dir = os.path.join(os.getcwd(), "tests")
|
||||
loader.load_project_tests(project_dir)
|
||||
loader.load_debugtalk_module(project_dir)
|
||||
loader.project_working_directory = os.path.join(os.getcwd(), "tests")
|
||||
loader.load_project_tests(loader.project_working_directory)
|
||||
loader.load_debugtalk_module(loader.project_working_directory)
|
||||
project_mapping = loader.project_mapping
|
||||
self.assertEqual(project_mapping["debugtalk"]["variables"]["SECRET_KEY"], "DebugTalk")
|
||||
self.assertIn("get_token", project_mapping["def-api"])
|
||||
self.assertIn("setup_and_reset", project_mapping["def-testcase"])
|
||||
self.assertEqual(project_mapping["env"]["PROJECT_KEY"], "ABCDEFGH")
|
||||
|
||||
Reference in New Issue
Block a user