Simpler PyTest parametrization
Project description
pytest-parametrization
Simpler PyTest parametrization
How to install
pip install pytest-parametrization
How to use
Explicit parameters
from parametrization import Parametrization
@Parametrization.parameters("actual", "expected")
@Parametrization.case(name="some_case_0", actual=1, expected=2)
@Parametrization.case("some_case_1", actual=1, expected=2)
@Parametrization.case("some_case_2", 1, expected=1)
@Parametrization.case("some_case_3", 2, 2)
@Parametrization.case("some_case_4", 3, 3)
def test_somthing(actual, expected):
assert actual == expected
Auto-detect parameters
from parametrization import Parametrization
@Parametrization.autodetect_parameters()
@Parametrization.case(name="some_case_0", actual=1, expected=2)
@Parametrization.case("some_case_1", actual=1, expected=2)
@Parametrization.case("some_case_2", actual=1, expected=1)
def test_somthing(actual, expected):
assert actual == expected
Auto-detect parameters with default parameter
from parametrization import Parametrization
@Parametrization.autodetect_parameters()
@Parametrization.default_parameters(expected=None)
@Parametrization.case(name="some_case_0", actual=1, expected=2)
@Parametrization.case("some_case_1", actual=1, expected=2)
@Parametrization.case("some_case_2", actual=1, expected=1)
@Parametrization.case("some_case_2", actual=1)
def test_somthing(actual, expected):
assert actual == expected
Generate name based on arguments
from parametrization import Parametrization
@Parametrization.name_factory(lambda actual, expected: '{}=={}'.format(actual, expected))
@Parametrization.case(actual=1, expected=1)
@Parametrization.case(actual=2, expected=2)
@Parametrization.case('special-name', actual=3, expected=3)
def test_somthing(actual, expected):
assert actual == expected
As can be seen from the example, you can also give explicit name for a case even if you are using name factory.
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
File details
Details for the file pytest-parametrization-2022.2.1.tar.gz
.
File metadata
- Download URL: pytest-parametrization-2022.2.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.8.2 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 057229ad7e284fe3435a717a8a58dc5f169b3d1e5aa946d94ec591d31bd78445 |
|
MD5 | 85cd1f4536274c53647e5799f59232c5 |
|
BLAKE2b-256 | 5843c3459bd30ffdb9df4b23bdffa7febf141227d0a2b6701f0443f3ed7fcfb5 |