From 28cfb628add51649c12d0e8f03b54c2e5ef65121 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 21 May 2020 12:50:54 +0800 Subject: [PATCH 01/13] fix: ensure referenced testcase share the same session --- docs/CHANGELOG.md | 6 ++++++ examples/postman_echo/request_methods/conf.py | 0 httprunner/runner.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) delete mode 100644 examples/postman_echo/request_methods/conf.py diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2e794dd4..44ce45d1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 3.0.5 (2020-05-21) + +**Fixed** + +- fix: ensure referenced testcase share the same session + ## 3.0.4 (2020-05-19) **Added** diff --git a/examples/postman_echo/request_methods/conf.py b/examples/postman_echo/request_methods/conf.py deleted file mode 100644 index e69de29b..00000000 diff --git a/httprunner/runner.py b/httprunner/runner.py index df2824f5..95219187 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -68,7 +68,6 @@ class HttpRunner(object): parsed_request_dict["json"] = parsed_request_dict.pop("req_json", {}) # request - self.__session = self.__session or HttpSession() resp = self.__session.request(method, url, **parsed_request_dict) resp_obj = ResponseObject(resp) @@ -184,6 +183,7 @@ class HttpRunner(object): parse_config(self.config) self.__start_at = time.time() self.__step_datas: List[StepData] = [] + self.__session = self.__session or HttpSession() self.__session_variables = {} for step in self.teststeps: # update with config variables From 293df5a1913e7e6d5912dc3aab25ae69c0178c36 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 21 May 2020 15:57:31 +0800 Subject: [PATCH 02/13] feat: add default header for each testcase #721 --- docs/CHANGELOG.md | 4 ++++ httprunner/__init__.py | 2 +- httprunner/runner.py | 12 ++++++++++++ pyproject.toml | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 44ce45d1..a87ecc09 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ ## 3.0.5 (2020-05-21) +**Added** + +- feat: add default header `HRUN-Request-ID` for each testcase #721 + **Fixed** - fix: ensure referenced testcase share the same session diff --git a/httprunner/__init__.py b/httprunner/__init__.py index 1c9ba758..36b1d4d9 100644 --- a/httprunner/__init__.py +++ b/httprunner/__init__.py @@ -1,4 +1,4 @@ -__version__ = "3.0.4" +__version__ = "3.0.5" __description__ = "One-stop solution for HTTP(S) testing." from httprunner.runner import HttpRunner diff --git a/httprunner/runner.py b/httprunner/runner.py index 95219187..a3ab7315 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -1,5 +1,6 @@ import os import time +import uuid from datetime import datetime from typing import List, Dict, Text @@ -31,6 +32,7 @@ class HttpRunner(object): success: bool = True # indicate testcase execution result __project_meta: ProjectMeta = None + __hrun_request_id: Text = None __step_datas: List[StepData] = None __session: HttpSession = None __session_variables: VariablesMapping = {} @@ -45,6 +47,10 @@ class HttpRunner(object): self.__session = session return self + def with_request_id(self, hrun_request_id: Text) -> "HttpRunner": + self.__hrun_request_id = hrun_request_id + return self + def with_variables(self, variables: VariablesMapping) -> "HttpRunner": self.__session_variables = variables return self @@ -60,6 +66,10 @@ class HttpRunner(object): parsed_request_dict = parse_data( request_dict, step.variables, self.__project_meta.functions ) + parsed_request_dict["headers"].setdefault( + "HRUN-Request-ID", + f"{self.__hrun_request_id}-{str(int(time.time() * 1000))[-6:]}", + ) # prepare arguments method = parsed_request_dict.pop("method") @@ -131,6 +141,7 @@ class HttpRunner(object): case_result = ( HttpRunner() .with_session(self.__session) + .with_request_id(self.__hrun_request_id) .with_variables(step_variables) .run_path(ref_testcase_path) ) @@ -183,6 +194,7 @@ class HttpRunner(object): parse_config(self.config) self.__start_at = time.time() self.__step_datas: List[StepData] = [] + self.__hrun_request_id = self.__hrun_request_id or f"HRUN-{uuid.uuid4()}" self.__session = self.__session or HttpSession() self.__session_variables = {} for step in self.teststeps: diff --git a/pyproject.toml b/pyproject.toml index 6614464f..5c47f4bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "httprunner" -version = "3.0.4" +version = "3.0.5" description = "One-stop solution for HTTP(S) testing." license = "Apache-2.0" readme = "README.md" From 2f7e8d744691df93bd215bfec10de362f2476ac6 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 21 May 2020 17:34:51 +0800 Subject: [PATCH 03/13] feat: builtin allure report --- docs/CHANGELOG.md | 1 + httprunner/runner.py | 4 +++- poetry.lock | 36 +++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a87ecc09..94777e44 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,7 @@ **Added** - feat: add default header `HRUN-Request-ID` for each testcase #721 +- feat: builtin allure report **Fixed** diff --git a/httprunner/runner.py b/httprunner/runner.py index a3ab7315..b6ed0fbb 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -1,6 +1,7 @@ import os import time import uuid +import allure from datetime import datetime from typing import List, Dict, Text @@ -207,7 +208,8 @@ class HttpRunner(object): step.variables, self.__project_meta.functions ) # run step - extract_mapping = self.__run_step(step) + with allure.step(f"step: {step.name}"): + extract_mapping = self.__run_step(step) # save extracted variables to session variables self.__session_variables.update(extract_mapping) diff --git a/poetry.lock b/poetry.lock index 8cc0bcd1..e373caa9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -12,6 +12,32 @@ version = "0.2.2" python = "<3.7" version = "2.4" +[[package]] +category = "main" +description = "Allure pytest integration" +name = "allure-pytest" +optional = false +python-versions = "*" +version = "2.8.15" + +[package.dependencies] +allure-python-commons = "2.8.15" +pytest = ">=4.5.0" +six = ">=1.9.0" + +[[package]] +category = "main" +description = "Common module for integrate allure with python-based frameworks" +name = "allure-python-commons" +optional = false +python-versions = "*" +version = "2.8.15" + +[package.dependencies] +attrs = ">=16.0.0" +pluggy = ">=0.4.0" +six = ">=1.9.0" + [[package]] category = "main" description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." @@ -516,7 +542,7 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["jaraco.itertools", "func-timeout"] [metadata] -content-hash = "be53fb0cd423bac9dda129a958a58026009a99a455081333d7af51c22a4df8cf" +content-hash = "67027f8f78c61b981f3c01613ded1da2a0256a28fb92f95dd2d642b3fd1b43a5" python-versions = "^3.6" [metadata.files] @@ -524,6 +550,14 @@ aiocontextvars = [ {file = "aiocontextvars-0.2.2-py2.py3-none-any.whl", hash = "sha256:885daf8261818767d8f7cbd79f9d4482d118f024b6586ef6e67980236a27bfa3"}, {file = "aiocontextvars-0.2.2.tar.gz", hash = "sha256:f027372dc48641f683c559f247bd84962becaacdc9ba711d583c3871fb5652aa"}, ] +allure-pytest = [ + {file = "allure-pytest-2.8.15.tar.gz", hash = "sha256:27f9c75194e95ba069ee2d6d2a2615ed6c7e96617ff9a492ab3a74f3f4e64be2"}, + {file = "allure_pytest-2.8.15-py3-none-any.whl", hash = "sha256:62512bbce3d39b27a8e7ffbfb24e08e99c43df29b4f345168dfc9692bfddef71"}, +] +allure-python-commons = [ + {file = "allure-python-commons-2.8.15.tar.gz", hash = "sha256:c4768e5e1350fe2eb6e1c9dac6158dcb82e23de80c83c4fc6d71765c207c1408"}, + {file = "allure_python_commons-2.8.15-py3-none-any.whl", hash = "sha256:88ad53109b6fa57e6b721f4eab59116db6037e219bf54e1f196a222ba5e2dcfe"}, +] appdirs = [ {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, diff --git a/pyproject.toml b/pyproject.toml index 5c47f4bf..9a499654 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ loguru = "^0.4.1" jmespath = "^0.9.5" black = "^19.10b0" pytest = "^5.4.2" +allure-pytest = "^2.8.15" [tool.poetry.dev-dependencies] coverage = "^4.5.4" From 3003faeb19def0182a09416aadb11192bfa613f8 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 21 May 2020 17:47:03 +0800 Subject: [PATCH 04/13] change: remove default added -s option for hrun --- docs/CHANGELOG.md | 4 ++++ httprunner/cli.py | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 94777e44..179d48e7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,10 @@ - fix: ensure referenced testcase share the same session +**Changed** + +- change: remove default added `-s` option for hrun + ## 3.0.4 (2020-05-19) **Added** diff --git a/httprunner/cli.py b/httprunner/cli.py index f5f5655f..3b36a25b 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -40,9 +40,6 @@ def main_run(extra_args): sys.exit(1) extra_args_new.extend(testcase_path_list) - if "-s" not in extra_args_new: - extra_args_new.insert(0, "-s") - pytest.main(extra_args_new) From 94f218edba5a913476c3360410f4103c97b2255f Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 21 May 2020 18:07:56 +0800 Subject: [PATCH 05/13] change: update allure report meta, title and description --- httprunner/runner.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/httprunner/runner.py b/httprunner/runner.py index b6ed0fbb..6ea435f4 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -198,6 +198,11 @@ class HttpRunner(object): self.__hrun_request_id = self.__hrun_request_id or f"HRUN-{uuid.uuid4()}" self.__session = self.__session or HttpSession() self.__session_variables = {} + + # update allure report meta + allure.dynamic.title(self.config.name) + allure.dynamic.description(f"Request ID Prefix: {self.__hrun_request_id}") + for step in self.teststeps: # update with config variables step.variables.update(self.config.variables) From 0b388bd514517b7348b91e271ecf6c957b60c6af Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 21 May 2020 18:39:44 +0800 Subject: [PATCH 06/13] feat: each testcase has an unique id in uuid4 format --- docs/CHANGELOG.md | 1 + httprunner/runner.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 179d48e7..f8ee6cc0 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,7 @@ **Added** +- feat: each testcase has an unique id in uuid4 format - feat: add default header `HRUN-Request-ID` for each testcase #721 - feat: builtin allure report diff --git a/httprunner/runner.py b/httprunner/runner.py index 6ea435f4..5ada8032 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -33,7 +33,7 @@ class HttpRunner(object): success: bool = True # indicate testcase execution result __project_meta: ProjectMeta = None - __hrun_request_id: Text = None + __case_id: Text = None __step_datas: List[StepData] = None __session: HttpSession = None __session_variables: VariablesMapping = {} @@ -48,8 +48,8 @@ class HttpRunner(object): self.__session = session return self - def with_request_id(self, hrun_request_id: Text) -> "HttpRunner": - self.__hrun_request_id = hrun_request_id + def with_case_id(self, case_id: Text) -> "HttpRunner": + self.__case_id = case_id return self def with_variables(self, variables: VariablesMapping) -> "HttpRunner": @@ -69,7 +69,7 @@ class HttpRunner(object): ) parsed_request_dict["headers"].setdefault( "HRUN-Request-ID", - f"{self.__hrun_request_id}-{str(int(time.time() * 1000))[-6:]}", + f"HRUN-{self.__case_id}-{str(int(time.time() * 1000))[-6:]}", ) # prepare arguments @@ -142,7 +142,7 @@ class HttpRunner(object): case_result = ( HttpRunner() .with_session(self.__session) - .with_request_id(self.__hrun_request_id) + .with_case_id(self.__case_id) .with_variables(step_variables) .run_path(ref_testcase_path) ) @@ -174,7 +174,9 @@ class HttpRunner(object): """main entrance""" self.config = testcase.config self.teststeps = testcase.teststeps - self.config.variables.update(self.__session_variables) + + self.__case_id = self.__case_id or str(uuid.uuid4()) + logger.info(f"Start to run testcase: {self.config.name}, TestCase ID: {self.__case_id}") if self.config.path: self.__project_meta = load_project_meta(self.config.path) @@ -192,16 +194,16 @@ class HttpRunner(object): config.base_url, config.variables, self.__project_meta.functions ) + self.config.variables.update(self.__session_variables) parse_config(self.config) self.__start_at = time.time() self.__step_datas: List[StepData] = [] - self.__hrun_request_id = self.__hrun_request_id or f"HRUN-{uuid.uuid4()}" self.__session = self.__session or HttpSession() self.__session_variables = {} # update allure report meta allure.dynamic.title(self.config.name) - allure.dynamic.description(f"Request ID Prefix: {self.__hrun_request_id}") + allure.dynamic.description(f"TestCase ID: {self.__case_id}") for step in self.teststeps: # update with config variables From 9a5bfa18286d1e431c5060e805e49962dd1ca534 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 22 May 2020 12:14:10 +0800 Subject: [PATCH 07/13] feat: dump log for each testcase --- docs/CHANGELOG.md | 3 +- httprunner/client.py | 2 +- httprunner/runner.py | 81 +++++++++++++++++++++++++++----------------- httprunner/schema.py | 5 +-- 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f8ee6cc0..90a7953b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,12 +1,13 @@ # Release History -## 3.0.5 (2020-05-21) +## 3.0.5 (2020-05-22) **Added** - feat: each testcase has an unique id in uuid4 format - feat: add default header `HRUN-Request-ID` for each testcase #721 - feat: builtin allure report +- feat: dump log for each testcase **Fixed** diff --git a/httprunner/client.py b/httprunner/client.py index b7e645a7..a72e770f 100644 --- a/httprunner/client.py +++ b/httprunner/client.py @@ -192,7 +192,7 @@ class HttpSession(requests.Session): logger.info( f"status_code: {response.status_code}, " f"response_time(ms): {response_time_ms} ms, " - f"response_length: {content_size} bytes\n" + f"response_length: {content_size} bytes" ) return response diff --git a/httprunner/runner.py b/httprunner/runner.py index 5ada8032..0966749f 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -33,12 +33,15 @@ class HttpRunner(object): success: bool = True # indicate testcase execution result __project_meta: ProjectMeta = None - __case_id: Text = None + __case_id: Text = "" __step_datas: List[StepData] = None __session: HttpSession = None __session_variables: VariablesMapping = {} - __start_at = 0 - __duration = 0 + # time + __start_at: float = 0 + __duration: float = 0 + # log + __log_path: Text = "" def with_project_meta(self, project_meta: ProjectMeta) -> "HttpRunner": self.__project_meta = project_meta @@ -170,41 +173,36 @@ class HttpRunner(object): logger.info(f"run step end: {step.name} <<<<<<\n") return step_data.export - def run(self, testcase: TestCase): - """main entrance""" - self.config = testcase.config - self.teststeps = testcase.teststeps - - self.__case_id = self.__case_id or str(uuid.uuid4()) - logger.info(f"Start to run testcase: {self.config.name}, TestCase ID: {self.__case_id}") - - if self.config.path: - self.__project_meta = load_project_meta(self.config.path) + def __parse_config(self, config: TConfig): + if config.path: + self.__project_meta = load_project_meta(config.path) elif not self.__project_meta: self.__project_meta = ProjectMeta() - def parse_config(config: TConfig): - config.variables = parse_variables_mapping( - config.variables, self.__project_meta.functions - ) - config.name = parse_data( - config.name, config.variables, self.__project_meta.functions - ) - config.base_url = parse_data( - config.base_url, config.variables, self.__project_meta.functions - ) + config.variables.update(self.__session_variables) + config.variables = parse_variables_mapping( + config.variables, self.__project_meta.functions + ) + config.name = parse_data( + config.name, config.variables, self.__project_meta.functions + ) + config.base_url = parse_data( + config.base_url, config.variables, self.__project_meta.functions + ) - self.config.variables.update(self.__session_variables) - parse_config(self.config) + def run(self, testcase: TestCase): + """run testcase""" + self.config = testcase.config + self.teststeps = testcase.teststeps + + # prepare + self.__parse_config(self.config) self.__start_at = time.time() self.__step_datas: List[StepData] = [] self.__session = self.__session or HttpSession() self.__session_variables = {} - # update allure report meta - allure.dynamic.title(self.config.name) - allure.dynamic.description(f"TestCase ID: {self.__case_id}") - + # run teststeps for step in self.teststeps: # update with config variables step.variables.update(self.config.variables) @@ -252,6 +250,7 @@ class HttpRunner(object): return TestCaseSummary( name=self.config.name, success=self.success, + case_id=self.__case_id, time=TestCaseTime( start_at=self.__start_at, start_at_iso_format=start_at_iso_format, @@ -260,9 +259,29 @@ class HttpRunner(object): in_out=TestCaseInOut( vars=self.config.variables, export=self.get_export_variables() ), + log=self.__log_path, step_datas=self.__step_datas, ) def test_start(self): - """discovered by pytest""" - return self.run(TestCase(config=self.config, teststeps=self.teststeps)) + """main entrance, discovered by pytest""" + self.__case_id = self.__case_id or str(uuid.uuid4()) + self.__log_path = self.__log_path or os.path.join( + "logs", f"{self.__case_id}.run.log" + ) + log_handler = logger.add(self.__log_path, level="DEBUG") + + # update allure report meta + # TODO: parse config name + allure.dynamic.title(self.config.name) + allure.dynamic.description(f"TestCase ID: {self.__case_id}") + + logger.info( + f"Start to run testcase: {self.config.name}, TestCase ID: {self.__case_id}" + ) + + try: + return self.run(TestCase(config=self.config, teststeps=self.teststeps)) + finally: + logger.remove(log_handler) + logger.info(f"generate testcase log: {self.__log_path}") diff --git a/httprunner/schema.py b/httprunner/schema.py index feae1fb5..cf0d5dc3 100644 --- a/httprunner/schema.py +++ b/httprunner/schema.py @@ -147,8 +147,9 @@ class StepData(BaseModel): class TestCaseSummary(BaseModel): - name: Text = "" - success: bool = False + name: Text + success: bool + case_id: Text time: TestCaseTime in_out: TestCaseInOut = {} log: Text = "" From 988e7e6e781b0b2e30cd2ed6c6c34e80831fda46 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 22 May 2020 13:13:46 +0800 Subject: [PATCH 08/13] fix: parse config name --- httprunner/loader.py | 7 +++++-- httprunner/runner.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/httprunner/loader.py b/httprunner/loader.py index 937fabb0..5e6234ed 100644 --- a/httprunner/loader.py +++ b/httprunner/loader.py @@ -410,6 +410,11 @@ def load_project_meta(test_path: Text) -> ProjectMeta: environments and debugtalk.py functions. """ + project_meta = ProjectMeta() + + if not test_path: + return project_meta + if test_path in project_meta_cached_mapping: return project_meta_cached_mapping[test_path] @@ -417,8 +422,6 @@ def load_project_meta(test_path: Text) -> ProjectMeta: test_path ) - project_meta = ProjectMeta() - # load .env file # NOTICE: # environment variable maybe loaded in debugtalk.py diff --git a/httprunner/runner.py b/httprunner/runner.py index 0966749f..f3f2fb3c 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -174,11 +174,6 @@ class HttpRunner(object): return step_data.export def __parse_config(self, config: TConfig): - if config.path: - self.__project_meta = load_project_meta(config.path) - elif not self.__project_meta: - self.__project_meta = ProjectMeta() - config.variables.update(self.__session_variables) config.variables = parse_variables_mapping( config.variables, self.__project_meta.functions @@ -196,6 +191,7 @@ class HttpRunner(object): self.teststeps = testcase.teststeps # prepare + self.__project_meta = self.__project_meta or load_project_meta(self.config.path) self.__parse_config(self.config) self.__start_at = time.time() self.__step_datas: List[StepData] = [] @@ -271,8 +267,15 @@ class HttpRunner(object): ) log_handler = logger.add(self.__log_path, level="DEBUG") + # parse config name + self.__project_meta = self.__project_meta or load_project_meta(self.config.path) + variables = self.config.variables + variables.update(self.__session_variables) + self.config.name = parse_data( + self.config.name, variables, self.__project_meta.functions + ) + # update allure report meta - # TODO: parse config name allure.dynamic.title(self.config.name) allure.dynamic.description(f"TestCase ID: {self.__case_id}") From 41a188df3f99fa7850c249b3b85eec5ceb9cbedf Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 22 May 2020 13:28:56 +0800 Subject: [PATCH 09/13] feat: log request cookies --- httprunner/client.py | 2 ++ httprunner/schema.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/httprunner/client.py b/httprunner/client.py index a72e770f..f5474ce3 100644 --- a/httprunner/client.py +++ b/httprunner/client.py @@ -41,6 +41,7 @@ def get_req_resp_record(resp_obj: Response) -> ReqRespData: # record actual request info request_headers = dict(resp_obj.request.headers) + request_cookies = dict(resp_obj.request._cookies) request_body = resp_obj.request.body try: request_body = json.loads(request_body) @@ -57,6 +58,7 @@ def get_req_resp_record(resp_obj: Response) -> ReqRespData: method=resp_obj.request.method, url=resp_obj.request.url, headers=request_headers, + cookies=request_cookies, body=request_body, ) diff --git a/httprunner/schema.py b/httprunner/schema.py index cf0d5dc3..86c1a13c 100644 --- a/httprunner/schema.py +++ b/httprunner/schema.py @@ -13,6 +13,7 @@ BaseUrl = Union[HttpUrl, Text] VariablesMapping = Dict[Text, Any] FunctionsMapping = Dict[Text, Callable] Headers = Dict[Text, Text] +Cookies = Dict[Text, Text] Verify = bool Hook = List[Text] Export = List[Text] @@ -53,7 +54,7 @@ class Request(BaseModel): headers: Headers = {} req_json: Dict = Field({}, alias="json") data: Union[Text, Dict[Text, Any]] = "" - cookies: Dict[Text, Text] = {} + cookies: Cookies = {} timeout: int = 120 allow_redirects: bool = True verify: Verify = False @@ -108,13 +109,13 @@ class RequestData(BaseModel): method: MethodEnum = MethodEnum.GET url: Url headers: Headers = {} - # TODO: add cookies + cookies: Cookies = {} body: Union[Text, bytes, Dict, None] = {} class ResponseData(BaseModel): status_code: int - cookies: Dict + cookies: Cookies encoding: Union[Text, None] = None headers: Dict content_type: Text From 21f34d00825f1e860a10a106d8eb9b1b379f1285 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 22 May 2020 14:47:12 +0800 Subject: [PATCH 10/13] test: add test for debugging pytest --- httprunner/cli_test.py | 5 +++++ httprunner/schema.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/httprunner/cli_test.py b/httprunner/cli_test.py index db7f9651..20a4c8cb 100644 --- a/httprunner/cli_test.py +++ b/httprunner/cli_test.py @@ -2,6 +2,8 @@ import io import sys import unittest +import pytest + from httprunner.cli import main @@ -36,3 +38,6 @@ class TestCli(unittest.TestCase): from httprunner import __description__ self.assertIn(__description__, self.captured_output.getvalue().strip()) + + def test_debug_pytest(self): + pytest.main(["-s", "examples/postman_echo/request_methods/request_with_variables_test.py"]) diff --git a/httprunner/schema.py b/httprunner/schema.py index 86c1a13c..c6c0fe97 100644 --- a/httprunner/schema.py +++ b/httprunner/schema.py @@ -115,9 +115,9 @@ class RequestData(BaseModel): class ResponseData(BaseModel): status_code: int + headers: Dict cookies: Cookies encoding: Union[Text, None] = None - headers: Dict content_type: Text body: Union[Text, bytes, Dict] From a8be9c86c0f645d8da5b2653371ad582e17b812c Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 22 May 2020 14:52:35 +0800 Subject: [PATCH 11/13] docs: add examples for session_fixture and testcase_fixture --- examples/postman_echo/conftest.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 examples/postman_echo/conftest.py diff --git a/examples/postman_echo/conftest.py b/examples/postman_echo/conftest.py new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/examples/postman_echo/conftest.py @@ -0,0 +1,2 @@ + + From 579f6b41e1c4032dfb5bc86df38b3b2651f6f95e Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 22 May 2020 15:08:45 +0800 Subject: [PATCH 12/13] change: format code with black --- httprunner/cli.py | 4 ++-- httprunner/cli_test.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/httprunner/cli.py b/httprunner/cli.py index 3b36a25b..a8140484 100644 --- a/httprunner/cli.py +++ b/httprunner/cli.py @@ -5,9 +5,9 @@ import sys import pytest from loguru import logger -from httprunner import __description__, __version__, exceptions +from httprunner import __description__, __version__ from httprunner.ext.har2case import init_har2case_parser, main_har2case -from httprunner.ext.make import init_make_parser, main_make, convert_testcase_path +from httprunner.ext.make import init_make_parser, main_make from httprunner.ext.scaffold import init_parser_scaffold, main_scaffold diff --git a/httprunner/cli_test.py b/httprunner/cli_test.py index 20a4c8cb..a344866c 100644 --- a/httprunner/cli_test.py +++ b/httprunner/cli_test.py @@ -40,4 +40,9 @@ class TestCli(unittest.TestCase): self.assertIn(__description__, self.captured_output.getvalue().strip()) def test_debug_pytest(self): - pytest.main(["-s", "examples/postman_echo/request_methods/request_with_variables_test.py"]) + pytest.main( + [ + "-s", + "examples/postman_echo/request_methods/request_with_variables_test.py", + ] + ) From 2f15179f31e7219fbda6040483fa581fd03f78f7 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 22 May 2020 15:14:18 +0800 Subject: [PATCH 13/13] fix: github action, test package installation --- .github/workflows/integration_test.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index da6cc0be..6064459e 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -30,14 +30,13 @@ jobs: poetry build ls dist/*.whl | xargs pip install # test installation hrun -V - hrun run -h - hrun startproject -h - hrun har2case -h - pip install locustio - hrun locusts -h + har2case -h + httprunner run -h + httprunner startproject -h + httprunner har2case -h - name: Run smoketest - postman echo run: | - hrun examples/postman_echo/request_methods + hrun -s examples/postman_echo/request_methods - name: Run smoketest - httpbin run: | - hrun examples/httpbin/ + hrun -s examples/httpbin/