pytest-variables is a plugin for pytest that provides a mechanism to supply external variables to tests and fixtures. It allows defining variables in various file formats (JSON, YAML, TOML, HJSON) and making them accessible as a dictionary fixture within your pytest test suite. The current version is 3.1.0, and it follows a regular release cadence with major versions indicating breaking changes.
pip install pytest-variablesVerified import paths — ran on the pinned version, not inferred.
Create a variable file (e.g., `variables.json`) and then use the `--variables` command-line option with pytest. The variables will be available as a `variables` fixture in your tests. Environment variables can be used as fallbacks within the variable files.
Upgrade Python to 3.8+ or pin `pytest-variables` to `<3.1.0`.
Avoid directly accessing internal plugin attributes. Use the `variables` fixture for all variable access.
Be mindful of the order when specifying multiple variable files. Place more specific or overriding configurations later in the command-line argument list.
Verify the `yaml_loader` setting in `pytest.ini` (e.g., `[pytest] yaml_loader = SafeLoader`) matches the expected case and loader type if encountering YAML parsing issues.