0

In my Tavern test file, I save a variable like so:

[...]
save:
  headers:
    csrf: x-csrf-token
[...]

When I run pytest, it logs this warning:

tavern/util/dict_util.py:119: FutureWarning: In a future version of Tavern, selecting for values to save in nested objects will have to be done as a JMES path query - see http://jmespath.org/ for more information

JMESPath.org isn't of much help, and neither is Tavern's documentation. The 'x-csrf-token' field is not nested inside 'headers', so I don't understand the warning. I've tried two different JMES-like-syntaxes, but both give me "cant find key" errors instead:

save:
  csrf: headers.x-csrf-token

save:
  headers:
    csrf: headers.x-csrf-token

What exactly is Tavern expecting here?

Mossmyr
  • 909
  • 2
  • 10
  • 26

1 Answers1

1

JMESPath unquoted identifiers cannot contain hyphens. You can use a quoted identifier instead. Try:

save:
  headers:
    csrf: '"x-csrf-token"'

The single quotes are needed to tell YAML that the double-quotes are part of the string. The double quotes in JMESPath allow you to include characters that would otherwise be allowed in an identifier, such as hyphens.

Weeble
  • 17,058
  • 3
  • 60
  • 75