Mercurial > piecrust2
diff tests/conftest.py @ 1096:2aa6174453c8
tests: Better error reporting for serving tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 17 Feb 2018 11:51:06 -0800 |
parents | 63f118c773ee |
children | be550e1f6423 |
line wrap: on
line diff
--- 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):