Plugin for providing variables to pytest tests/fixtures
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
pytest_variables Remove try/except block as it is no longer required Jan 15, 2018
.gitignore Add .tox to .gitignore Mar 18, 2016
.travis.yml Restore testing against Python 3.4 and 3.5 in Travis CI Jan 15, 2018
README.rst Update release notes for v1.7.0 Aug 8, 2017
setup.cfg Configure package as py2, py3 universal wheel Sep 26, 2016 Switch to setuptools_scm for managing versions Feb 28, 2017



pytest-variables is a plugin for pytest that provides variables to tests/fixtures as a dictionary via a file specified on the command line.

License PyPI Travis Issues Requirements


You will need the following prerequisites in order to use pytest-variables:

  • Python 2.7, 3.6, PyPy, or PyPy3
  • pytest 2.6 or newer


To install pytest-variables:

$ pip install pytest-variables

Additional formats

The following optional formats are supported, but must be explicitly installed as they require additional dependencies:

Human JSON

Human JSON is a configuration file format that caters to humans and helps reduce the errors they make. To install Human JSON support:

$ pip install pytest-variables[hjson]


YAML is a human friendly data serialization standard for all programming languages. To install YAML support:

$ pip install pytest-variables[yaml]

Specifying variables

Use the --variables command line option one or more times to specify paths to files containing your variables:

$ pytest --variables firefox-53.json --variables windows-10.json

with the following contents for the firefox-53.json file:

  "capabilities": {
    "browser": "Firefox",
    "browser_version": "53.0"

and another file named windows-10.json with:

  "capabilities": {
    "os": "Windows",
    "os_version": "10",
    "resolution": "1280x1024"

you'll get the merged version of your variables:

  "capabilities": {
    "browser": "Firefox",
    "browser_version": "53.0",
    "os": "Windows",
    "os_version": "10",
    "resolution": "1280x1024"

If multiple files are specified then they will be applied in the order they appear on the command line. When duplicate keys with non dictionary values are encountered, the last to be applied will take priority.

Accessing variables

With a JSON variables file such as:

  "foo": "bar",
  "bar": "foo"

Specify the variables funcarg to make the variables available to your tests. The contents of the files are made available as a dictionary:

def test_foo(self, variables):
    assert variables['foo'] == 'bar'
    assert variables.get('bar') == 'foo'
    assert variables.get('missing') is None