Create pytest parametrize decorators from external files.
Project description
pytest-param-files
A small package to create pytest parametrize decorators 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 with_parameters
decorator 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")
@with_parameters(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:
@with_parameters(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+other
Installation
Install from PyPI:
$ pip install pytest-param-files
or install locally (for development):
$ pip install -e .
Other formats
TODO ...
Regenerating expected output on failures
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
File details
Details for the file pytest_param_files-0.2.0.tar.gz
.
File metadata
- Download URL: pytest_param_files-0.2.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d656edbac352bf303f7acc023eb3ef81cd91d879e4a6465a9d7e0028b28f834d |
|
MD5 | 2cd85ce369093384d8f70845710ce7c0 |
|
BLAKE2b-256 | 9daa23f10d8c42dc49831f8ed81ac65109015b7f00d22db576b4005f97fa0b10 |
Provenance
File details
Details for the file pytest_param_files-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_param_files-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ce1d40f25501d50b02a1c6b69ea877a202908c37b2c5139d37d08b2fd5cd0d4 |
|
MD5 | 06a036688e34f57a10febba6a7bf5d22 |
|
BLAKE2b-256 | 82294a142f0f24044e44b129e40d19e1701704b75cb936c70aec64e81edf3f10 |