Skip to main content

Create pytest parametrize decorators from external files.

Project description

pytest-param-files

PyPI

A small package to generate parametrized pytests from external files.

Simply create a text file with the following (dot) format:

[name1] description
.
input content
.
expected output content
,

[name2] description
.
input content
.
expected output content
,

Then, use the param_file pytest marker to create a parametrized test:

from pathlib import Path
from pytest_param_files import with_parameters

import my_function

PATH = Path(__file__).parent.joinpath("test_file.txt")

@pytest.mark.param_file(PATH, fmt="dot")
def test_function(file_params):
    assert my_function(file_params.content) == file_params.expected

and the output will be:

$ pytest -v test_file.py
...
test_file.py::test_function[1-name1] PASSED
test_file.py::test_function[8-name2] FAILED

Alternatively use the assert_expected method, which will can handle more rich assertion features:

@pytest.mark.param_file(PATH, fmt="dot")
def test_function(file_params):
    actual = my_function(file_params.content)
    assert file_params.assert_expected(actual, rstrip=True)
$ pytest -v test_file.py
...
test_file.py::test_function[1-name1] PASSED
test_file.py::test_function[8-name2] FAILED
...
E       AssertionError: Actual does not match expected
E       --- /path/to/test_file.txt:8
E       +++ (actual)
E       @@ -1 +1 @@
E       -content
E       +other

Installation

Install from PyPI:

$ pip install pytest-param-files

or install locally (for development):

$ pip install -e .

Regenerating expected output on failures

EXPERIMENTAL

Running pytest with the --regen-file-failure option will regenerate the parameter file with actual output, if any test fails.

Other formats

TODO ...

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_param_files-0.3.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

pytest_param_files-0.3.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_param_files-0.3.0.tar.gz.

File metadata

  • Download URL: pytest_param_files-0.3.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for pytest_param_files-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3e07a8b69ad4fc674fb487ba8350ffcf8ec499f766a2942fcf412a02c54366af
MD5 7858b9646b8effe454f1a9dbc6dd2a89
BLAKE2b-256 02030837751f02bb060e98d3f11bba12f58145e76fc674a7f6c3b78144bc0fd7

See more details on using hashes here.

Provenance

File details

Details for the file pytest_param_files-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_param_files-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9989ac501f6f4b6153761e0c778c534f20dba1b44817bd86a1d032d561c5676f
MD5 46854556c404a14d8a67453a5342fbfd
BLAKE2b-256 d4a1d32938441bf12dc744ab3b7f161bd52a40c98206949605b9804209887ea3

See more details on using hashes here.

Provenance

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