Skip to main content

Create pytest parametrize decorators from external files.

Project description

pytest-param-files

PyPI

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


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

Uploaded Source

Built Distribution

pytest_param_files-0.2.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_param_files-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5664d06eb273829c038db6e826ce7db8be0edaf93c38cc607d2b38f485e593be
MD5 2617771e12fc7911374bca07103e8fec
BLAKE2b-256 d4f4d75f617ea262db31bb8c68b955a968f94203ff06afcc13604bf505e589a5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pytest_param_files-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 04127a4af16dc2c50ec76624bb9d0266cd11af0391a2cb77ebf06005816476a0
MD5 3dfac7e3aae932c050e7ea344044a360
BLAKE2b-256 f3b331098ca3a59bcdb63d74731c498f93db0856f6bd28e4248f274f6885ccde

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