pytest plugin: avoid repeating arguments in parametrize
Project description
This is an alternative to the rejected pull request #780 of pytest.
Installation
Just get it from PyPI:
python3 -m pip install pytest-auto-parametrize --user
Usage
This is an example for the usage of a parametrized test without using this plugin:
import pytest
testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]
@pytest.mark.parametrize('a, b, c, d, e, f, g', testparams)
def test_many_args(a, b, c, d, e, f, g):
assert d == 4
The argument list has to be repeated, which is annoying.
By using this plugin, the repetition can be avoided:
import pytest
testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]
@pytest.auto_parametrize(testparams)
def test_many_args(a, b, c, d, e, f, g):
assert d == 4
The auto-deduced parameters must be in the beginning of the parameter list, but any other parameters can be used afterwards, e.g. fixtures:
import pytest
testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]
@pytest.fixture
def myfixture():
return 4
@pytest.auto_parametrize(testparams)
def test_many_args_and_fixture(a, b, c, d, e, f, g, myfixture):
assert d - myfixture == 0
Limitations
Unlike @pytest.mark.parametrize(...) the decorator @pytest.auto_parametrize(...) cannot be used multiple times for the same test function. It can be used together with one or multiple instances of @pytest.mark.parametrize(...), though, as long as the “auto” arguments are in the beginning of the argument list.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-auto-parametrize-0.1.0.tar.gz
.
File metadata
- Download URL: pytest-auto-parametrize-0.1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5187d9f720c58d749538977734c0b5ac2436fbcd6bf875c7e7162550e44bce56 |
|
MD5 | 34785f0f1eb44aff593e73a879f527c5 |
|
BLAKE2b-256 | 98c7ef8743a3b3489a59b811e33c3977e01ec550311198f6c88dd21f36de853a |
File details
Details for the file pytest_auto_parametrize-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_auto_parametrize-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8abe810a55af4fe920f55b1a1986e34ba3095d4d0a02424b9f906405b8a604b3 |
|
MD5 | f22a4b7a4a076585460141bd9649ce89 |
|
BLAKE2b-256 | 1f9f0e315c050f1d939252efa9237e746ac657614ab77e4186a639fd4ca708cf |