From 52922bc2f0d367368a19b59092c4ecd06771abb4 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 2 Aug 2016 12:20:47 +0200 Subject: [PATCH] Provide meaningful error messages in functional tests The default python-requests error message does not contain response body, so it's not possible to figure out the actual cause of the failure. Change it to a custom exception including the cause. Change-Id: I83ea035ab2b3ace4dbdf5b17cd5d632c4c704003 --- ironic_inspector/test/functional.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ironic_inspector/test/functional.py b/ironic_inspector/test/functional.py index af5beb46d..5e27b8543 100644 --- a/ironic_inspector/test/functional.py +++ b/ironic_inspector/test/functional.py @@ -69,6 +69,10 @@ def get_test_conf_file(): return TEST_CONF_FILE +def get_error(response): + return response.json()['error']['message'] + + class Base(base.NodeTest): ROOT_URL = 'http://127.0.0.1:5050' IS_FUNCTIONAL = True @@ -115,7 +119,11 @@ class Base(base.NodeTest): if expect_error: self.assertEqual(expect_error, res.status_code) else: - res.raise_for_status() + if res.status_code >= 400: + msg = ('%(meth)s %(url)s failed with code %(code)s: %(msg)s' % + {'meth': method.upper(), 'url': endpoint, + 'code': res.status_code, 'msg': get_error(res)}) + raise AssertionError(msg) return res def call_introspect(self, uuid, new_ipmi_username=None,