mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +08:00
change: generate logs folder in current working directory
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
- remove support for Python 2.7
|
||||
- replace string format with f-string
|
||||
- remove dependency colorama and colorlog
|
||||
- generate reports folder in current working directory
|
||||
- generate reports/logs folder in current working directory
|
||||
|
||||
## 2.5.7 (2020-02-21)
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ def load_project_data(test_path, dot_env_path=None):
|
||||
# locate PWD and load debugtalk.py functions
|
||||
project_mapping["PWD"] = project_working_directory
|
||||
project_mapping["functions"] = debugtalk_functions
|
||||
project_mapping["test_path"] = os.path.abspath(test_path)
|
||||
project_mapping["test_path"] = os.path.abspath(test_path)[len(project_working_directory)+1:]
|
||||
|
||||
return project_mapping
|
||||
|
||||
|
||||
@@ -596,24 +596,23 @@ def dump_json_file(json_data, json_file_abs_path):
|
||||
def prepare_dump_json_file_abs_path(project_mapping, tag_name):
|
||||
""" prepare dump json file absolute path.
|
||||
"""
|
||||
pwd_dir_path = project_mapping.get("PWD") or os.getcwd()
|
||||
current_working_dir = os.getcwd()
|
||||
test_path = project_mapping.get("test_path")
|
||||
|
||||
if not test_path:
|
||||
# running passed in testcase/testsuite data structure
|
||||
dump_file_name = f"tests_mapping.{tag_name}.json"
|
||||
dumped_json_file_abs_path = os.path.join(pwd_dir_path, "logs", dump_file_name)
|
||||
dumped_json_file_abs_path = os.path.join(current_working_dir, "logs", dump_file_name)
|
||||
return dumped_json_file_abs_path
|
||||
|
||||
# both test_path and pwd_dir_path are absolute path
|
||||
logs_dir_path = os.path.join(pwd_dir_path, "logs")
|
||||
test_path_relative_path = test_path[len(pwd_dir_path)+1:]
|
||||
logs_dir_path = os.path.join(current_working_dir, "logs")
|
||||
|
||||
if os.path.isdir(test_path):
|
||||
file_foder_path = os.path.join(logs_dir_path, test_path_relative_path)
|
||||
file_foder_path = os.path.join(logs_dir_path, test_path)
|
||||
dump_file_name = f"all.{tag_name}.json"
|
||||
else:
|
||||
file_relative_folder_path, test_file = os.path.split(test_path_relative_path)
|
||||
file_relative_folder_path, test_file = os.path.split(test_path)
|
||||
file_foder_path = os.path.join(logs_dir_path, file_relative_folder_path)
|
||||
test_file_name, _file_suffix = os.path.splitext(test_file)
|
||||
dump_file_name = f"{test_file_name}.{tag_name}.json"
|
||||
|
||||
@@ -278,26 +278,22 @@ class TestUtils(unittest.TestCase):
|
||||
|
||||
def test_prepare_dump_json_file_path_for_folder(self):
|
||||
# hrun tests/httpbin/a.b.c/ --save-tests
|
||||
project_working_directory = os.path.join(os.getcwd(), "tests")
|
||||
project_mapping = {
|
||||
"PWD": project_working_directory,
|
||||
"test_path": os.path.join(os.getcwd(), "tests", "httpbin", "a.b.c")
|
||||
"test_path": os.path.join("tests", "httpbin", "a.b.c")
|
||||
}
|
||||
self.assertEqual(
|
||||
utils.prepare_dump_json_file_abs_path(project_mapping, "loaded"),
|
||||
os.path.join(project_working_directory, "logs", "httpbin/a.b.c/all.loaded.json")
|
||||
os.path.join(os.getcwd(), "logs", "tests/httpbin/a.b.c/all.loaded.json")
|
||||
)
|
||||
|
||||
def test_prepare_dump_json_file_path_for_file(self):
|
||||
# hrun tests/httpbin/a.b.c/rpc.yml --save-tests
|
||||
project_working_directory = os.path.join(os.getcwd(), "tests")
|
||||
project_mapping = {
|
||||
"PWD": project_working_directory,
|
||||
"test_path": os.path.join(os.getcwd(), "tests", "httpbin", "a.b.c", "rpc.yml")
|
||||
"test_path": os.path.join("tests", "httpbin", "a.b.c", "rpc.yml")
|
||||
}
|
||||
self.assertEqual(
|
||||
utils.prepare_dump_json_file_abs_path(project_mapping, "loaded"),
|
||||
os.path.join(project_working_directory, "logs", "httpbin/a.b.c/rpc.loaded.json")
|
||||
os.path.join(os.getcwd(), "logs", "tests/httpbin/a.b.c/rpc.loaded.json")
|
||||
)
|
||||
|
||||
def test_prepare_dump_json_file_path_for_passed_testcase(self):
|
||||
@@ -307,5 +303,5 @@ class TestUtils(unittest.TestCase):
|
||||
}
|
||||
self.assertEqual(
|
||||
utils.prepare_dump_json_file_abs_path(project_mapping, "loaded"),
|
||||
os.path.join(project_working_directory, "logs", "tests_mapping.loaded.json")
|
||||
os.path.join(os.getcwd(), "logs", "tests_mapping.loaded.json")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user