I'm using tavern to make multiple similar request to a web server, but in the same stage of different tests (ie different YAML files). Each web request takes a long time, so I've split up my overall testing into different test files so that I can use python-xdist
to run the tests in parallel. This means I gain nothing by combining all tests as separate stages of the same test.
It seems I can reuse a complete JSON body stored in a JSON or YAML file using !include
(see Directly including test data). However, I want to reuse a partial JSON body and then add/override just the parameters that differ for each test (see Reusing requests and YAML fragments")
For example, a test file looks like this:
Option 1: intermediate variables for includes
variables:
request_template: &reqtemp
!include components/request.yaml
stages:
- name: Create infrastructure
request:
url: "{service:s}"
json:
<<: *reqtemp
# Here I start extending the template with values specific to the test
name: "infrastructure_name"
param_1: "param_for_test_1"
param_2: "another param for test 1"
However, when running a test like this, it will throw an exception expected a mapping or list of mappings for merging, but found scalar
. I've tried other syntax options like the below, but still get the same error:
Option 2: no variables
stages:
- name: Create infrastructure
request:
url: "{service:s}"
json:
<<: !include components/request.yaml
# Here I start extending the template with values specific to the test
name: "infrastructure_name"
param_1: "param_for_test_1"
param_2: "another param for test 1"
How can I get the benefit of importing a large request body with !include
yet be able to modify it on a per-stage basis?