Skip to main content

pytest-param-files

PyPI

A small package to generate parametrized pytests from external files.

Simply create a text file with an available format:

dot format (default):

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

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

yaml format:

name1:
  description: optional description
  input: |-
    input content
  expected: |-
    expected output content
name2:
  description: optional description
  input: |-
    input content
  expected: |-
    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

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

Other formats

TODO ...

Release files for pytest_param_files 0.6.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_param_files 0.6.0
File Size Uploaded
pytest_param_files-0.6.0.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest_param_files 0.6.0
File Interpreter ABI Platform
pytest_param_files-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / pytest_param_files-0.6.0.tar.gz

Download URL pytest_param_files-0.6.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ab02608d63f7baf14483682ee6213c9330401f2a14d7a63489b872f6830a9848
BLAKE2b-256 checksum
How to use checksums
f754023b260066b36cc8ebd42c52c7c65b94110c4a1abb08d0edf7eac71e21a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release files / pytest_param_files-0.6.0-py3-none-any.whl

Download URL pytest_param_files-0.6.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d24095dbc98bdc1e1d8236c0e01237c8a3dc3e3e7742e0f552304c4073691251
BLAKE2b-256 checksum
How to use checksums
460993188af48b8dcd7c615bf32c4e248fc096ea826ae0e9bfd3f65acc9de826
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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