# HG changeset patch # User Ludovic Chabant # Date 1518897066 28800 # Node ID 2aa6174453c88ec85c06f61f004c9093095eaf17 # Parent c8518f5cedbbd52369b597e824c47f894cceff4e tests: Better error reporting for serving tests. diff -r c8518f5cedbb -r 2aa6174453c8 tests/conftest.py --- a/tests/conftest.py Sat Feb 17 11:50:42 2018 -0800 +++ b/tests/conftest.py Sat Feb 17 11:51:06 2018 -0800 @@ -246,7 +246,7 @@ return self.fspath, 0, "bake: %s" % self.name def repr_failure(self, excinfo): - if isinstance(excinfo.value, ExpectedChefOutputError): + if isinstance(excinfo.value, UnexpectedChefOutputError): return ('\n'.join( ['Unexpected command output. Left is expected output, ' 'right is actual output'] + @@ -254,7 +254,7 @@ return super(ChefTestItem, self).repr_failure(excinfo) -class ExpectedChefOutputError(Exception): +class UnexpectedChefOutputError(Exception): pass @@ -349,7 +349,12 @@ client = Client(server, BaseResponse) resp = client.get(url) - assert expected_status == resp.status_code + if expected_status != resp.status_code: + raise UnexpectedChefServingError( + url, + "Expected HTTP status '%s', got '%s'" % + (expected_status, resp.status_code), + resp) if expected_headers: for k, v in expected_headers.items(): @@ -380,9 +385,21 @@ excinfo.value.description]) res += repr_nested_failure(excinfo) return res + elif isinstance(excinfo.value, UnexpectedChefServingError): + res = str(excinfo.value) + res += '\nWhile requesting URL: %s' % excinfo.value.url + res += '\nBody:\n%s' % excinfo.value.resp.data.decode('utf8') + return res return super(ServeTestItem, self).repr_failure(excinfo) +class UnexpectedChefServingError(Exception): + def __init__(self, url, msg, resp): + super().__init__(msg) + self.url = url + self.resp = resp + + class ServeTestFile(YamlTestFileBase): __item_class__ = ServeTestItem @@ -454,9 +471,9 @@ def _compare_lists(left, right, ctx): for i in range(min(len(left), len(right))): - l = left[i] - r = right[i] - cmpres = _compare(l, r, ctx) + lc = left[i] + rc = right[i] + cmpres = _compare(lc, rc, ctx) if cmpres: return cmpres if len(left) > len(right):