# HG changeset patch # User Ludovic Chabant # Date 1528261133 25200 # Node ID 952f3c24a99d791ed5d4b11ed0c3f628db7b379a # Parent 5d9b2581b8a12923b0cd018941c5efddb6ea336c tests: Improve servings tests' error reporting. diff -r 5d9b2581b8a1 -r 952f3c24a99d tests/conftest.py --- a/tests/conftest.py Sun May 20 22:37:48 2018 -0700 +++ b/tests/conftest.py Tue Jun 05 21:58:53 2018 -0700 @@ -334,7 +334,7 @@ if isinstance(excinfo.value, UnexpectedBakeOutputError): return ('\n'.join( ['Unexpected bake output. Left is expected output, ' - 'right is actual output'] + + 'right is actual output.'] + excinfo.value.args[0])) elif isinstance(excinfo.value, BakeError): res = ('\n'.join( @@ -390,13 +390,19 @@ (expected_status, resp.status_code), resp) + cctx = CompareContext() + if expected_headers: for k, v in expected_headers.items(): - assert v == resp.headers.get(k) + cmpres = _compare_str(v, resp.headers.get(k), cctx) + if cmpres: + raise UnexpectedChefServingOutput(cmpres) actual = resp.data.decode('utf8').rstrip() if expected_output: - assert expected_output.rstrip() == actual + cmpres = _compare_str(expected_output.rstrip(), actual, cctx) + if cmpres: + raise UnexpectedChefServingOutput(cmpres) if expected_contains: assert expected_contains.rstrip() in actual @@ -424,6 +430,12 @@ res += '\nWhile requesting URL: %s' % excinfo.value.url res += '\nBody:\n%s' % excinfo.value.resp.data.decode('utf8') return res + elif isinstance(excinfo.value, UnexpectedChefServingOutput): + res = '\n'.join( + ["Unexpected serving output. Left is expected output, " + "right is actual output."] + + excinfo.value.args[0]) + return res return super(ServeTestItem, self).repr_failure(excinfo) @@ -434,6 +446,10 @@ self.resp = resp +class UnexpectedChefServingOutput(Exception): + pass + + class ServeTestFile(YamlTestFileBase): __item_class__ = ServeTestItem