Skip to main content

pytest plugin for providing variables to tests/fixtures

Project description

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

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

Installation

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

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 foo.json --variables 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 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

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.5.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

pytest_variables-1.5.0-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for pytest-variables-1.5.0.tar.gz
Algorithm Hash digest
SHA256 fdbaa293b255e14adcf04454d6f26f553f778fd5835b6c81b0148944a700dbc1
MD5 635729f3504fdc017829ea54203df3ff
BLAKE2b-256 530afe64653a41b424c7f438d3ced172dbc7c8c8809609ce49fc488eca752bc3

See more details on using hashes here.

File details

Details for the file pytest_variables-1.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_variables-1.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6784a2bf8c6c22c7d04a0e43db754178442a3ae8c924fc7b9d9e351b7cb1a3c8
MD5 a5a3c2729c883e38fbe75468be89d253
BLAKE2b-256 219fc4554b329ede1694c18ca13e37eea5b2fa91f763b98586b121e55ea179f3

See more details on using hashes here.

Supported by

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