Search code examples
apiyamlpytesttavern

Error "Expected only one document in this file but found multiple" in tavern


I use common.yaml file for sharing stages but If I add more than one stage it's showing error "tavern.util.exceptions.UnexpectedDocumentsError:". Do I have to add separate yams file for each stage?

My common.yaml file

name: Test /order endpoint status code and response
description:
  Reusable test stage to get listings

stages:
  - id: get_listings
    name: Test to get all the listings 
    request:
       url: 
      method: POST
      headers:
        Authorization: 
 ---
name: Test /status endpoint to create order
description:
  Reusable test stage for order creation

stages:
  - id: create_order
    name: Test to create an order
    skip: False
    request:
      url: 
      method: POST
      headers:
        Authorization: 

Testfile.yaml

test_name: Test endpoint

includes:
 - !include common.yaml

stages:

  - type: ref

    id: get_listings

  - type: ref1

    id: create_order

Solution

  • !include cannot handle a file with multiple documents since it basically replaces the current node with the content from the referred document, starting at its root node. Since a file with multiple documents has multiple root nodes, it's unclear what !include should do there.

    That being said, you can of course simply define both stages in the same document:

    # [snip]
    
    stages:
      - id: get_listings
        name: Test to get all the listings 
        request:
           url: 
          method: POST
          headers:
            Authorization:
      - id: create_order
        name: Test to create an order
        skip: False
        request:
          url: 
          method: POST
          headers:
            Authorization: