From 02ee791c5be0362174d38dd86ce603fa2de9d3ce Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 2 Jan 2020 22:33:34 +0800 Subject: [PATCH] fix #808: project_working_directory is not initialized when running passed in data structure --- docs/CHANGELOG.md | 1 + httprunner/api.py | 2 ++ httprunner/loader/__init__.py | 4 +++- httprunner/loader/locate.py | 6 +++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6211169f..4a712bbd 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,7 @@ - fix #826: Windows does not support file name include ":" - fix #819: maximum recursion error in locusts - fix #818: request missed url in setup_hooks +- fix #808: project_working_directory is not initialized when running passed in data structure ## 2.5.1 (2020-01-02) diff --git a/httprunner/api.py b/httprunner/api.py index 11666fed..8ca3aeaa 100644 --- a/httprunner/api.py +++ b/httprunner/api.py @@ -292,6 +292,8 @@ class HttpRunner(object): if loader.is_test_path(path_or_tests): return self.run_path(path_or_tests, dot_env_path, mapping) elif loader.is_test_content(path_or_tests): + project_working_directory = path_or_tests.get("project_mapping", {}).get("PWD", os.getcwd()) + loader.init_pwd(project_working_directory) return self.run_tests(path_or_tests) else: raise exceptions.ParamsError("Invalid testcase path or testcases: {}".format(path_or_tests)) diff --git a/httprunner/loader/__init__.py b/httprunner/loader/__init__.py index 36f44798..022cf410 100644 --- a/httprunner/loader/__init__.py +++ b/httprunner/loader/__init__.py @@ -9,7 +9,8 @@ HttpRunner loader """ from httprunner.loader.check import is_test_path, is_test_content, JsonSchemaChecker -from httprunner.loader.locate import get_project_working_directory as get_pwd +from httprunner.loader.locate import get_project_working_directory as get_pwd, \ + init_project_working_directory as init_pwd from httprunner.loader.load import load_csv_file, load_builtin_functions from httprunner.loader.buildup import load_cases, load_project_data @@ -18,6 +19,7 @@ __all__ = [ "is_test_content", "JsonSchemaChecker", "get_pwd", + "init_pwd", "load_csv_file", "load_builtin_functions", "load_project_data", diff --git a/httprunner/loader/locate.py b/httprunner/loader/locate.py index 0ac21161..fd23e4d2 100644 --- a/httprunner/loader/locate.py +++ b/httprunner/loader/locate.py @@ -62,7 +62,11 @@ def locate_debugtalk_py(start_path): def init_project_working_directory(test_path): """ this should be called at startup - init_project_working_directory <- load_project_data <- load_cases <- run + + run test file: + run_path -> load_cases -> load_project_data -> init_project_working_directory + or run passed in data structure: + run -> init_project_working_directory Args: test_path: specified testfile path