Skip to main content

pytest-scenario-files

Making Pytest Scenarios Easy and Scalable

PyPI pyversions Pytest

Hatch project Ruff Pre-Commit

pytest-scenario-files is a pytest plugin that runs tests using data loaded from files via parameterized fixtures.


Introduction

pytest has a feature called parameterization that allows you to run the same test function repeatedly using different inputs to test multiple scenarios. However, managing the test data for parameterization can be a problem. Sometimes the input data is very large or there are many test cases, so that it is impractical to put all of the data into the source code of the test.

This plug-in loads the data for the test scenarios from separate data files that are automatically matched up against the test functions. Each function can have one or more data files associated with it, and each file can contain multiple scenarios. The data files can be in JSON or YAML format.

Features

  • Loads data for scenarios from files into fixtures
  • Multiple scenario data sets may be in one file
  • There may be multiple data files for each test
  • Fixtures may refer to fixtures in other files
  • Can specify indirect parameterization
  • Intuitive and sane data file structure
  • Integration with Responses
  • Can load native Responses files
  • Integration with Respx
  • NEW - AI Skill available - published to skills.sh and skillMD

Compatibility

This package is a plug-in for pytest and works with Python 3.11 and up.

  • Tested with pytest versions 7.4, 8.4, and 9.1.
  • Tested with CPython 3.11-3.15 (including 3.14t and 3.15t).

Documentation

For more information on advanced usages, read the detailed documentation.


Quickstart

Installation

Install pytest-scenario-files from PyPI by using pip :

$ pip install pytest-scenario-files

Add Fixtures

For each test where you want to have data loaded from a file, add the name of a fixture to the list of arguments for the test. For instance, if you have a target function:

def foo(x):
    return 3 * x

And a test function:

def test_foo():
    assert foo(17) == 51

You can set up test_foo() for scenarios by adding two fixtures:

def test_foo(input_value, expected_result):
    assert foo(input_value) == expected_result

Create a Data File

A data file will be loaded if it matches all of the following criteria:

  1. The filename starts with data_, followed by the name of the test function with the prefix test_ removed. The remainder of the filename may be any value, and is usually used to identify the tests contained in the file.
  2. The filename must end in .json, .yaml, or .yml.
  3. The file is contained in a folder at or below the file that contains the test.

For this example, create a YAML file with the name data_foo_scenarios_1.yaml.

Inside the file, set up a structure with two levels of nested dictionaries.

  1. The top level is the name of each scenario.
  2. The second level has the name of each fixture with value assignments.
scenario_1:
  input_value: 17
  expected_result: 51
scenario_2:
  input_value: 7
  expected_result: 21
scenario_string:
  input_value: a
  expected_result: aaa
scenario_list:
  input_value:
    - x
  expected_result:
    - x
    - x
    - x

Run the Tests

$ pytest -vv -rA

You will see the test run four times, each with a different input value and expected result. (The option -vv gives verbose output; the option -rA prints all logging and output from the tests. Neither is necessary, but they're nice to have.)


Reporting Issues

If you encounter any problems, please file an issue including a detailed description and (if possible) an example of the problem.

License

Distributed under the terms of the MIT license, pytest-scenario-files is free and open source software.

Metadata

Release files for pytest-scenario-files 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-scenario-files 1.4.0
File Size Uploaded Provenance
pytest_scenario_files-1.4.0.tar.gz 57.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-scenario-files 1.4.0
File Interpreter ABI Platform
pytest_scenario_files-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 76.0 kB

Release files / pytest_scenario_files-1.4.0.tar.gz

Download URL pytest_scenario_files-1.4.0.tar.gz
Size 57.1 kB
Tags Source
SHA-256 checksum
How to use checksums
03a97dffdc5b47d2dc8ea2bb82a8f4199b85ebe50af41c27a99f393ff44d936f
BLAKE2b-256 checksum
How to use checksums
d997d4d1475b576af6e23b85e51ef4a0d128fe8818ed1a1a2f6d8c70312729ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / pytest_scenario_files-1.4.0-py3-none-any.whl

Download URL pytest_scenario_files-1.4.0-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8648e73436fb7970d5ca0c4114e3d7122948904a34446647264c8401d16b0df
BLAKE2b-256 checksum
How to use checksums
02e8bbea3c6e208ff4c6977592779496efdbab7977ccfc7a00a6438162311dc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for pytest-scenario-files 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_scenario_files-1.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page