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 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

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_variables-1.7.1-py2.py3-none-any.whl (7.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for pytest-variables-1.7.1.tar.gz
Algorithm Hash digest
SHA256 7808b77b643b9f8a24f1ee1c32132648b1c62ab93956f20fe101dde66db6d09a
MD5 455927e4f85bb7afe4f8aad1f99cb9f0
BLAKE2b-256 7945bc59f541c898d4fb475d19e1d9228d6281168383053bac631428cd38c04a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_variables-1.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 59c00b95779657532ac5f8209b28b5d447c8b4bc4210c1d6bdf9a42aa201f9b0
MD5 bca36a4cce9747a7d4d7e93b911764b9
BLAKE2b-256 c9443d7e29a985d978a24b32f5e08fc9eaff46c2aed6703b57f3e52d2f3ecbfb

See more details on using hashes here.

Supported by

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