Skip to main content

pytest plugin for providing variables to tests/fixtures

Project description

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

License PyPI Travis Issues Requirements

Requirements

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

  • Python 2.6, 2.7, 3.2, 3.3, 3.4 or PyPy

  • py.test 2.3 or newer

Installation

To install pytest-variables:

pip install pytest-variables

Specifying variables

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

py.test --variables foo.json bar.json

If multiple files are specified then they will be applied in the order they appear on the command line. When duplicates 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 JSON 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

Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-variables-1.1.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file pytest-variables-1.1.tar.gz.

File metadata

File hashes

Hashes for pytest-variables-1.1.tar.gz
Algorithm Hash digest
SHA256 72e79976c4086eef2dbbb04f8841f976e060c5506404c08e384df0689c795f17
MD5 07b063a2c7d241b0b17173c61bc5f600
BLAKE2b-256 66a48f11b0ccfa5c6c5466e24694d28dbb5691daa4ff93164013564e96311e14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page