Curly braces in JSON values of criteria causes error when test fails
Closed this issue · 1 comments
pcoccoli commented
Basically the same error as #812 but the curly braces are in the JSON value.
example_response.json:
{
"sample": "{c5548c42-b4c8-41a4-8f4f-e4c1a33bf0b1}"
}
Results in:
$ tavern-ci test_minimal.tavern.yaml
============================================================================ test session starts ============================================================================
platform linux -- Python 3.9.6, pytest-7.3.1, pluggy-0.13.1
rootdir: /home/pcoccoli/tmp/test
configfile: setup.cfg
plugins: anyio-3.6.2, typeguard-4.0.0, mock-3.10.0, cov-4.0.0, asyncio-0.20.3, allure-pytest-2.12.0, tavern-1.25.2
asyncio: mode=strict
collected 1 item
test_minimal.tavern.yaml
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/box/box.py", line 488, in __getitem__
INTERNALERROR> return super().__getitem__(item)
INTERNALERROR> KeyError: 'c5548c42-b4c8-41a4-8f4f-e4c1a33bf0b1'
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/util/dict_util.py", line 34, in _check_and_format_values
INTERNALERROR> would_replace = formatter.get_field(field_name, [], box_vars)[0]
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/lib/python3.9/string.py", line 270, in get_field
INTERNALERROR> obj = self.get_value(first, args, kwargs)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/lib/python3.9/string.py", line 227, in get_value
INTERNALERROR> return kwargs[key]
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/box/box.py", line 509, in __getitem__
INTERNALERROR> raise BoxKeyError(str(err)) from _exception_cause(err)
INTERNALERROR> box.exceptions.BoxKeyError: "'c5548c42-b4c8-41a4-8f4f-e4c1a33bf0b1'"
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/main.py", line 323, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/main.py", line 348, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/runner.py", line 114, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/runner.py", line 133, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/runner.py", line 224, in call_and_report
INTERNALERROR> report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR> gen.send(outcome)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/skipping.py", line 266, in pytest_runtest_makereport
INTERNALERROR> rep = outcome.get_result()
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/runner.py", line 368, in pytest_runtest_makereport
INTERNALERROR> return TestReport.from_item_and_call(item, call)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/_pytest/reports.py", line 359, in from_item_and_call
INTERNALERROR> longrepr = item.repr_failure(excinfo)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/testutils/pytesthook/item.py", line 256, in repr_failure
INTERNALERROR> attach_text(str(error), name="error_output")
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/testutils/pytesthook/error.py", line 227, in __str__
INTERNALERROR> return self.longreprtext
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/testutils/pytesthook/error.py", line 223, in longreprtext
INTERNALERROR> self.toterminal(tw)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/testutils/pytesthook/error.py", line 212, in toterminal
INTERNALERROR> self._print_formatted_stage(tw, stage)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/testutils/pytesthook/error.py", line 149, in _print_formatted_stage
INTERNALERROR> formatted_stage = format_keys(stage, keys)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/util/dict_util.py", line 116, in format_keys
INTERNALERROR> formatted[key] = format_keys(val[key], box_vars)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/util/dict_util.py", line 116, in format_keys
INTERNALERROR> formatted[key] = format_keys(val[key], box_vars)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/util/dict_util.py", line 116, in format_keys
INTERNALERROR> formatted[key] = format_keys(val[key], box_vars)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/util/dict_util.py", line 122, in format_keys
INTERNALERROR> formatted = _check_and_format_values(val, box_vars)
INTERNALERROR> File "/home/pcoccoli/.pyenv/versions/3.9.6/envs/v396/lib/python3.9/site-packages/tavern/util/dict_util.py", line 40, in _check_and_format_values
INTERNALERROR> raise exceptions.MissingFormatError(field_name) from e
INTERNALERROR> tavern.util.exceptions.MissingFormatError: c5548c42-b4c8-41a4-8f4f-e4c1a33bf0b1
michaelboulton commented
Sorry I thought I'd replied to this earlier, I did look at it a bit - this isn't easy to solve because Tavern assumes it can format that data it loads in (because it is actually 'loaded' by Tavern, it's injected into the test dictionary object by the Yaml library) and the only way to get around it is to, I think, make your json file yaml and use the !raw
tag with it like
tavern/tests/integration/881_2.yaml
Line 1 in 722b40b
https://github.com/taverntesting/tavern/blob/722b40b786d7933e0243e47996922b45114fdb08/tests/integration/881_2.yaml
See also : #881 (comment)