Create pytest parametrize decorators from external files.
Project description
pytest-param-files
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
import pytest
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pytest_param_files-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11e20bfd382341502a5b1334095a00445411f371a29769cb5fd8a97b58d4054a |
|
MD5 | 2bc9f2f70a21221e2f9b8e6fa203e8e9 |
|
BLAKE2b-256 | b622e972dc4eedc61fe7b69f1e0b31edf67fb0e41091f4b456bd30132b279ae8 |