pytest-variables
pytest plugin for providing variables to tests/fixtures
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-variablesuv
uv add pytest-variablespoetry
poetry add pytest-variablesInstalling 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
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytest-seleniumpytest-selenium is a pytest plugin that…
copyleft · top 15,000 on PyPI
pytest-metadataA pytest plugin that captures and exposes test…
copyleft · top 1,000 on PyPI
pytest-regressionsProvides pytest fixtures for writing regression…
permissive · top 5,000 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
pytest-envA pytest plugin that loads environment…
permissive · top 1,000 on PyPI
pytest-helpers-namespaceProvides a pytest namespace for registering and…
permissive · top 15,000 on PyPI
pytest-lazy-fixturesAllows you to reference pytest fixtures…
permissive · top 5,000 on PyPI
pytest-playwrightA pytest plugin that integrates Playwright…
permissive · top 5,000 on PyPI
pytest-htmlGenerates HTML reports for pytest test results,…
copyleft · top 1,000 on PyPI