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


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

Uploaded Source

Built Distribution

pytest_param_files-0.3.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_param_files-0.3.3.tar.gz
Algorithm Hash digest
SHA256 7e0d60b7070c87be9e99bc139d0b34ab8a694cf65957d7e5f099fdf929a12578
MD5 4eba0db6aef474d0d6e67f7da6248072
BLAKE2b-256 359a4f4bb1d415da02719431ede33bf67ba6ed6aa4ac5811ad69ebbfd2aee680

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_param_files-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4f531ef5a528e6136270504598350ea04c00e1f2ec296a6dcdd7bda32c3873de
MD5 3999db5f7b04ffa6bc323ef297445c64
BLAKE2b-256 60e7b8f4bb9dfee36c2ad37f211804ea58a7bd086187a4dbd8e9e891e452f729

See more details on using hashes here.

Supported by

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