Skip to content

BadSchemaError: "Additional properties are not allowed #968

@ErcinDedeoglu

Description

@ErcinDedeoglu
  • Tavern version: 2.16.0
  • Python version: 3.10.0
  • pytest version: 7.2.2
  • OS: Linux

I'm encountering a BadSchemaError when trying to run a Tavern test that includes stages via !include and attempts to save response data. The error message indicates:
Additional properties are not allowed ('save' was unexpected)

test_name: Test GET /knowledge-bases/{knowledge_base_id}/content/overview


stages:
  - !include ../../stages/login_stage.yaml
  - !include ../../stages/create_knowledge_base_stage.yaml
  - name: Get Knowledge Base Content Overview
    request:
      url: "{host}/api/v1/knowledge-bases/{knowledge_base_id}/content/overview"
      method: GET
      headers:
        Authorization: "Bearer {access_token}"
    response:
      status_code: 200
      headers:
        content-type: application/json
      json:
        files: !anything
        total_files: !anything
    save:
      json:
        content_overview: "$"

stages/create_knowledge_base_stage.yaml:

name: create_knowledge_base
request:
  url: "{host}/api/v1/knowledge-bases"
  method: POST
  headers:
    Authorization: "Bearer {access_token}"
    Content-Type: "application/json"
  json:
    name: "Test KB {random_string}"
    description: "A test knowledge base created by Tavern tests"
response:
  status_code: 201
  headers:
    content-type: application/json
  json:
    id: !re_match "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
    name: !re_match "Test KB .*"
    description: "A test knowledge base created by Tavern tests"
    created_at: !re_match ".*T.*Z"
    updated_at: !re_match ".*T.*Z"
    is_deleted: false
    preprocessing_method_id: !anything
    ingestion_method_id: !anything
    digestion_method_id: !anything
  save:
    json:
      knowledge_base_id: id

Error Details
The error occurs during schema validation, specifically:

tavern._core.exceptions.BadSchemaError: 
---
Additional properties are not allowed ('save' was unexpected)
/tests/knowledge-bases/test_get_knowledge_base_content_overview.tavern.yaml: line 2-21:

What I've Tried

  1. Initially had a variables section at the test level, removed it
  2. Ensured consistent YAML indentation
  3. Removed any deprecated keys like verify_response_with
  4. Confirmed included stage files are valid Tavern stages
  5. Reduced the test to minimal components

Questions:

  1. Is save not allowed in test stages when using !include? The documentation suggests save should be valid at the stage level.
  2. Should save be placed differently when stages are included via !include?
  3. Is there a known issue with schema validation when combining !include with save directives?
  4. What's the correct way to save response data from a stage that's defined inline (not via !include)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions