skillfed

pytest-variables

pytest plugin for providing variables to tests/fixtures

pytest-variables v3.1.0 660.9K downloads/30d#5,455 on PyPI75
Copyleft license Active released

What it is and what it does

pytest-variables is a pytest plugin that externalizes test configuration by loading variables from files into tests as a dictionary. Instead of hardcoding test data or environment values, you specify one or more JSON, YAML, TOML, or Human JSON files via the --variables command-line flag, and the plugin merges them and injects the result into any test that requests the variables fixture. Multiple files are merged in order, with later values overriding earlier ones for non-dictionary keys.

The plugin is useful for test suites that need to run against different configurations—different browsers, operating systems, API endpoints, or credentials—without modifying test code. It supports optional formats (YAML, TOML, Human JSON) via extras, allowing you to choose the file format that best suits your team's workflow. It has a single runtime dependency (pytest) and is actively maintained with support for current Python versions.

Use it for:

  • Load browser and OS capabilities for cross-browser Selenium tests from separate JSON files.
  • Inject API endpoints, credentials, or feature flags into integration tests via YAML configuration.
  • Parameterize test data (hostnames, ports, timeouts) without modifying test code.
  • Merge environment-specific variables (dev, staging, prod) from multiple TOML files.
  • Share test configuration across a team via version-controlled variable files.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A pytest plugin that loads test variables from JSON, YAML, TOML, or Human JSON files specified on the command line and makes them available to tests as a dictionary.

Yes. It is a stable, actively maintained plugin with low install friction and no security vulnerabilities. The copyleft license is standard for pytest plugins and poses no barrier for most test suites. Install it if your tests need to consume external configuration files or if you want to separate test data from test code.

Install

pytest-variables on PyPI

pip

pip install pytest-variables

uv

uv add pytest-variables

poetry

poetry add pytest-variables

Installing pytest-variables

Before you install

Low friction install with only pytest as a runtime dependency. Actively maintained with recent commits; last release was in 2024 and the repository shows ongoing activity.

License in practice

Licensed under Mozilla Public License 2.0 (MPL 2.0), a copyleft license. You must disclose source code modifications and include the license with distributions, but can combine with proprietary code in larger works.

Quickstart

pip install pytest-variables

# Create variables.json:
# {"foo": "bar"}

# In test file:
def test_example(variables):
    assert variables['foo'] == 'bar'

Requires Python 3.8 or later; optional format support (YAML, TOML, Human JSON) requires installing extras like pytest-variables[yaml].

Verify before relying

  • Whether merging behavior for duplicate keys across multiple files is predictable enough for complex test suites.
  • Performance characteristics when loading very large variable files.

Package facts

License not declared (copyleft)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest
Maintenance actively maintained — 925 days since the last release
Last repo commit
First released
Downloads 660,940/month — #5,455 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_variables-3.1.0-py3-none-any.whl

Keywords: json, pytest, variables

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)Natural Language :: EnglishOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTopic :: Utilities

Tags

pytest variables from filepytest json configurationpytest test data injectionpytest yaml fixturespytest parameterized test data
test-configurationpytest-plugindata-driven-testing

More Utilities packages