From c2225b45ae46d11d8a6be6b843e1e34070faa1fe Mon Sep 17 00:00:00 2001 From: Michael Boulton Date: Sat, 2 Mar 2019 17:57:12 +0000 Subject: [PATCH] Fix missing rebased data [ci skip] --- tavern/_plugins/mqtt/response.py | 6 +++++- tavern/_plugins/rest/response.py | 10 ++++++++-- tavern/_plugins/rest/util.py | 2 +- tavern/testutils/newhooks.py | 1 + tavern/testutils/pytesthook/hooks.py | 7 +++++++ tavern/testutils/pytesthook/item.py | 2 ++ tavern/testutils/pytesthook/newhooks.py | 21 +++++++++++++++++++++ 7 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 tavern/testutils/pytesthook/newhooks.py diff --git a/tavern/_plugins/mqtt/response.py b/tavern/_plugins/mqtt/response.py index 2210941f..084b3558 100644 --- a/tavern/_plugins/mqtt/response.py +++ b/tavern/_plugins/mqtt/response.py @@ -90,7 +90,11 @@ def _await_response(self): msg.payload = msg.payload.decode("utf8") - self.test_block_config["tavern_internal"]["pytest_hook_caller"].pytest_tavern_log_response(response=get_paho_mqtt_response_information(msg)) + self.test_block_config["tavern_internal"][ + "pytest_hook_caller" + ].pytest_tavern_log_response( + response=get_paho_mqtt_response_information(msg) + ) if json_payload: try: diff --git a/tavern/_plugins/rest/response.py b/tavern/_plugins/rest/response.py index 794e43b3..e6fde0c5 100644 --- a/tavern/_plugins/rest/response.py +++ b/tavern/_plugins/rest/response.py @@ -90,7 +90,9 @@ def enc(v): log_dict_block(response_info["headers"], "Headers") log_dict_block(response_info["body"], "Body") if response_info.get("redirect_query_location"): - log_dict_block(response_info["redirect_query_location"], "Redirect location") + log_dict_block( + response_info["redirect_query_location"], "Redirect location" + ) def _get_redirect_query_params_with_err_check(self, response): """Call get_redirect_query_params, but also trigger an error if we @@ -156,7 +158,11 @@ def verify(self, response): """ self._verbose_log_response(response) - self.test_block_config["tavern_internal"]["pytest_hook_caller"].pytest_tavern_log_response(response=get_requests_response_information(response)) + self.test_block_config["tavern_internal"][ + "pytest_hook_caller" + ].pytest_tavern_log_response( + response=get_requests_response_information(response) + ) self.response = response self.status_code = response.status_code diff --git a/tavern/_plugins/rest/util.py b/tavern/_plugins/rest/util.py index 6e6c7b59..78635854 100644 --- a/tavern/_plugins/rest/util.py +++ b/tavern/_plugins/rest/util.py @@ -15,7 +15,7 @@ def get_redirect_query_params(response): else: parsed = urlparse(redirect_url) qp = parsed.query - redirect_query_params = {i:j[0] for i, j in parse_qs(qp).items()} + redirect_query_params = {i: j[0] for i, j in parse_qs(qp).items()} return redirect_query_params diff --git a/tavern/testutils/newhooks.py b/tavern/testutils/newhooks.py index c829cfa8..ed1b2713 100644 --- a/tavern/testutils/newhooks.py +++ b/tavern/testutils/newhooks.py @@ -1,5 +1,6 @@ # pylint: disable=unused-argument + def pytest_tavern_log_response(response): """Called when a response is obtained from a server diff --git a/tavern/testutils/pytesthook/hooks.py b/tavern/testutils/pytesthook/hooks.py index 21bc4546..6f7c53d3 100644 --- a/tavern/testutils/pytesthook/hooks.py +++ b/tavern/testutils/pytesthook/hooks.py @@ -48,3 +48,10 @@ def pytest_collect_file(parent, path): return YamlFile(path, parent) return None + + +def pytest_addhooks(pluginmanager): + """Add our custom tavern hooks""" + from . import newhooks + + pluginmanager.add_hookspecs(newhooks) diff --git a/tavern/testutils/pytesthook/item.py b/tavern/testutils/pytesthook/item.py index 7bda6575..f0f81b16 100644 --- a/tavern/testutils/pytesthook/item.py +++ b/tavern/testutils/pytesthook/item.py @@ -127,6 +127,8 @@ def runtest(self): load_plugins(self.global_cfg) + self.global_cfg["tavern_internal"] = {"pytest_hook_caller": self.config.hook} + # INTERNAL # NOTE - now that we can 'mark' tests, we could use pytest.mark.xfail # instead. This doesn't differentiate between an error in verification diff --git a/tavern/testutils/pytesthook/newhooks.py b/tavern/testutils/pytesthook/newhooks.py new file mode 100644 index 00000000..5a4ad7a7 --- /dev/null +++ b/tavern/testutils/pytesthook/newhooks.py @@ -0,0 +1,21 @@ +# pylint: disable=unused-argument + + +def pytest_tavern_log_response(response): + """Called when a response is obtained from a server + Todo: + This just takes 'response' at the moment, will need to be expanded to + take the filename and the test name/stage name as well. + """ + + +def pytest_tavern_before_request(stage): + """Called before each request""" + + +def pytest_tavern_after_request(stage): + """Called after each request, even if it fails + Note: + Some types of stages can run the request successfully, then fail later + on during verification. + """