I am using https://github.com/taverntesting/tavern but the following is likely really a PyYAML question.
We would like to have a directory of tests where each file matches an API endpoint.
api/v1/test_thing1.tavern.yaml
api/v1/test_thing2.tavern.yaml
and so on. Each YAML document will need a login
which could go in a common_stages.yaml
at the top of the tree. Most anything I have tried ends up with this error from PyYAML
yaml.scanner.ScannerError: mapping values are not allowed here
common_stages.yaml
looks like this:
---
stages:
- name: &login_required
request:
url: "{host}/api/v1/login"
json:
username: "{username}"
password: "{password}"
method: POST
headers:
content-type: application/json
response:
status_code: 201
cookies:
- session
headers:
content-type: application/json
and a test file looks like:
---
test_name: Get thing1 list
includes:
- !include ../../common.yaml
stages:
- name: Get category list
request:
url: "{host}/api/v1/thing1"
method: GET
response:
status_code: 200
headers:
content-type: application/json
I have tried adding the common_stages include to the list with common. I have tried including it on the stages
line of test_thing1.tavern.yaml
. No joy.
All of the Tavern examples show the YAML document as one long file. Which is fine for a demo but not a real world use.