Skip to main content

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

pytest-parametrization-2021.4.1.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file pytest-parametrization-2021.4.1.tar.gz.

File metadata

  • Download URL: pytest-parametrization-2021.4.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for pytest-parametrization-2021.4.1.tar.gz
Algorithm Hash digest
SHA256 460e61f4cd3e00b291277c94e36d37a47b277ecb21cb1921972a0b81e8a400dd
MD5 13883b6eceaebe08f197954ad79b1a10
BLAKE2b-256 cf7b61c36a1cdbdf24af65856cedcc0a17df5e2413f720ae39df1c016b7acc2a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page