Skip to main content

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.

Release files for pytest-auto-parametrize 0.1.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-auto-parametrize 0.1.0
File Size Uploaded
pytest-auto-parametrize-0.1.0.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-auto-parametrize 0.1.0
File Interpreter ABI Platform
pytest_auto_parametrize-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 7.6 kB

Release files / pytest-auto-parametrize-0.1.0.tar.gz

Download URL pytest-auto-parametrize-0.1.0.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5187d9f720c58d749538977734c0b5ac2436fbcd6bf875c7e7162550e44bce56
BLAKE2b-256 checksum
How to use checksums
98c7ef8743a3b3489a59b811e33c3977e01ec550311198f6c88dd21f36de853a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pytest_auto_parametrize-0.1.0-py2.py3-none-any.whl

Download URL pytest_auto_parametrize-0.1.0-py2.py3-none-any.whl
Size 4.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8abe810a55af4fe920f55b1a1986e34ba3095d4d0a02424b9f906405b8a604b3
BLAKE2b-256 checksum
How to use checksums
1f9f0e315c050f1d939252efa9237e746ac657614ab77e4186a639fd4ca708cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.0

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