Skip to main content

pytest-variables

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 3.7+ or PyPy3

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]

YAML Loader

You can specify which loader to use by setting yaml_loader in pytest.ini (or similar file) to one of the following:

  • BaseLoader

  • SafeLoader

  • FullLoader (default)

  • UnsafeLoader

[pytest]
yaml_loader = BaseLoader

Note that loader is case-sensitive.

To learn more about the loader, see here

TOML

TOML aims to be a minimal configuration file format that’s easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table. To install TOML support:

$ pip install pytest-variables[toml]

Contributing

We welcome contributions.

To learn more, see Development

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

Metadata

Release files for pytest-variables 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-variables 3.0.0
File Size Uploaded Provenance Actions
pytest_variables-3.0.0.tar.gz 7.3 kB Without provenance Details for pytest_variables-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-variables 3.0.0
File Interpreter ABI Platform Actions
pytest_variables-3.0.0-py3-none-any.whl Python 3 none any Details for pytest_variables-3.0.0-py3-none-any.whl

Total release size: 13.2 kB

Release files / pytest_variables-3.0.0.tar.gz

Download URL pytest_variables-3.0.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ab84235417afac5a0a7dd4c3918287d9c7329d2e16d570d6e943f8d8e02533b9
BLAKE2b-256 checksum
How to use checksums
6985ed733ee0ee9ff879512d44a54b2966eae94862c1f5ce1bc2535f74910ef3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / pytest_variables-3.0.0-py3-none-any.whl

Download URL pytest_variables-3.0.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
190d9d4da5a6013eb02df2049f6047d911cdbe44c5b1734a6acc1748433c93d0
BLAKE2b-256 checksum
How to use checksums
005589d360e448f8ab7db7bf8ace79802c6a231b67c5eefc66e8a53c121d26db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Security for pytest-variables 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page