Name | pytest_param_files JSON |
Version |
0.6.0
JSON |
| download |
home_page | None |
Summary | Create pytest parametrize decorators from external files. |
upload_time | 2023-07-29 12:28:38 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
pytest
parameterized
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pytest-param-files
[![PyPI][pypi-badge]][pypi-link]
A small package to generate parametrized [pytests](https://docs.pytest.org) 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:
```yaml
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:
```python
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:
```console
$ 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:
```python
@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)
```
```console
$ 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][pypi-link]:
```console
$ pip install pytest-param-files
```
or install locally (for development):
```console
$ 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 ...
[pypi-badge]: https://img.shields.io/pypi/v/pytest_param_files.svg
[pypi-link]: https://pypi.org/project/pytest_param_files
Raw data
{
"_id": null,
"home_page": null,
"name": "pytest_param_files",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "pytest,parameterized",
"author": null,
"author_email": "Chris Sewell <chrisj_sewell@hotmail.com>",
"download_url": "https://files.pythonhosted.org/packages/f7/54/023b260066b36cc8ebd42c52c7c65b94110c4a1abb08d0edf7eac71e21a5/pytest_param_files-0.6.0.tar.gz",
"platform": null,
"description": "# pytest-param-files\n\n[![PyPI][pypi-badge]][pypi-link]\n\nA small package to generate parametrized [pytests](https://docs.pytest.org) from external files.\n\nSimply create a text file with an available format:\n\n`dot` format (default):\n```\n[name1] description\n.\ninput content\n.\nexpected output content\n.\n\n[name2] description\n.\ninput content\n.\nexpected output content\n.\n```\n\n`yaml` format:\n```yaml\nname1:\n description: optional description\n input: |-\n input content\n expected: |-\n expected output content\nname2:\n description: optional description\n input: |-\n input content\n expected: |-\n expected output content\n```\n\nThen, use the `param_file` pytest marker to create a parametrized test:\n\n```python\nfrom pathlib import Path\nimport pytest\n\nimport my_function\n\nPATH = Path(__file__).parent.joinpath(\"test_file.txt\")\n\n@pytest.mark.param_file(PATH, fmt=\"dot\")\ndef test_function(file_params):\n assert my_function(file_params.content) == file_params.expected\n```\n\nand the output will be:\n\n```console\n$ pytest -v test_file.py\n...\ntest_file.py::test_function[1-name1] PASSED\ntest_file.py::test_function[8-name2] FAILED\n```\n\nAlternatively use the `assert_expected` method, which will can handle more rich assertion features:\n\n```python\n@pytest.mark.param_file(PATH, fmt=\"dot\")\ndef test_function(file_params):\n actual = my_function(file_params.content)\n assert file_params.assert_expected(actual, rstrip=True)\n```\n\n```console\n$ pytest -v test_file.py\n...\ntest_file.py::test_function[1-name1] PASSED\ntest_file.py::test_function[8-name2] FAILED\n...\nE AssertionError: Actual does not match expected\nE --- /path/to/test_file.txt:8\nE +++ (actual)\nE @@ -1 +1 @@\nE -content\nE +other\n```\n\n## Installation\n\nInstall from [PyPI][pypi-link]:\n\n```console\n$ pip install pytest-param-files\n```\n\nor install locally (for development):\n\n```console\n$ pip install -e .\n```\n\n## Regenerating expected output on failures\n\nRunning pytest with the `--regen-file-failure` option will regenerate the parameter file with actual output, if any test fails.\n\n## Other formats\n\nTODO ...\n\n[pypi-badge]: https://img.shields.io/pypi/v/pytest_param_files.svg\n[pypi-link]: https://pypi.org/project/pytest_param_files\n",
"bugtrack_url": null,
"license": null,
"summary": "Create pytest parametrize decorators from external files.",
"version": "0.6.0",
"project_urls": {
"Home": "https://github.com/chrisjsewell/pytest-param-files"
},
"split_keywords": [
"pytest",
"parameterized"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "460993188af48b8dcd7c615bf32c4e248fc096ea826ae0e9bfd3f65acc9de826",
"md5": "c0ca8023f1c2e2347d8d3068869f1e20",
"sha256": "d24095dbc98bdc1e1d8236c0e01237c8a3dc3e3e7742e0f552304c4073691251"
},
"downloads": -1,
"filename": "pytest_param_files-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c0ca8023f1c2e2347d8d3068869f1e20",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7107,
"upload_time": "2023-07-29T12:28:36",
"upload_time_iso_8601": "2023-07-29T12:28:36.265333Z",
"url": "https://files.pythonhosted.org/packages/46/09/93188af48b8dcd7c615bf32c4e248fc096ea826ae0e9bfd3f65acc9de826/pytest_param_files-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "f754023b260066b36cc8ebd42c52c7c65b94110c4a1abb08d0edf7eac71e21a5",
"md5": "cd9cc2b0c83e6d7bd98202459da2c884",
"sha256": "ab02608d63f7baf14483682ee6213c9330401f2a14d7a63489b872f6830a9848"
},
"downloads": -1,
"filename": "pytest_param_files-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "cd9cc2b0c83e6d7bd98202459da2c884",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9750,
"upload_time": "2023-07-29T12:28:38",
"upload_time_iso_8601": "2023-07-29T12:28:38.332741Z",
"url": "https://files.pythonhosted.org/packages/f7/54/023b260066b36cc8ebd42c52c7c65b94110c4a1abb08d0edf7eac71e21a5/pytest_param_files-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-29 12:28:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "chrisjsewell",
"github_project": "pytest-param-files",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "pytest_param_files"
}