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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_param_files-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c199237442074378c37e5e893721e21a7f587ba141022da8b17f559041e1cbf3
MD5 2e3c1a30dd2dae41ce65d415a876de5f
BLAKE2b-256 ce553c4864b95029b06e67f02f115225f46cdc3915be5685ce8619e6de7156f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_param_files-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34ca2dddb4bc6213d7eb8e74ee039eb91ec9f8708a170fe00bfd59024829e0d9
MD5 f6943426695505abb76179179e4ec9d7
BLAKE2b-256 252c831010070468db38bc588e9433f51edcaa05402cb76920372aaa25ab404f

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