Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/source/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,17 @@ request:
graphql_query: "{%raw%}{{ user(id: 123) {{ first_name }} }}{%endraw%}"
```

**NOTE**: This is a toy example, if you want to use GraphQL with tavern then
**NOTE**: This is a toy example, if you want to use GraphQL with tavern then
head over to the [GraphQL docs](./graphql.md).

**NOTE**: If a string value contains an unmatched `{` that is not a valid
format placeholder, Tavern will log a warning and pass the string through
unformatted rather than raising an error. For example, an MQTT payload value
like `{Explanation 1` would be passed through unchanged (logged as a warning),
whereas `{{Explanation 1}}` would be formatted to the literal string
`{Explanation 1}`. To avoid unexpected behaviour, always escape literal curly
braces as `{{` and `}}` as described above.

Since `0.5.0`, Tavern also has some 'magic' variables available in the `tavern`
key for formatting.

Expand Down
10 changes: 9 additions & 1 deletion tavern/_core/dict_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ def _check_and_format_values(to_format: str, box_vars: Box) -> str:
type(would_replace),
)

return to_format.format(**box_vars)
try:
return to_format.format(**box_vars)
except ValueError as e:
logger.warning(
"Failed to format string '%s': %s - passing through unformatted",
to_format,
e,
)
return to_format


def _attempt_find_include(to_format: str, box_vars: box.Box) -> str | None:
Expand Down
Loading