Skip to main content

pytest decorator for parametrizing test cases in a dict-way

Project description

image image image

GitHub Workflow Status pre-commit image

pytest-parametrize

pytest decorator for parametrizing test cases in a dict-way. It is an alternative for the pytest.mark.parametrize.

Usage

Decorate test function with test cases defined as a dictionary.

Example:

Simple

import pytest
from pytest_parametrize import parametrize

@parametrize(
    {
        "test-case-1": {"a": 1, "b": 2, "c": 3},
        "test-case-2": {"a": 2, "b": 3, "c": 5},
        "test-case-3": [
            {"a": 3, "b": 5, "c": 8},
            {"a": 5, "b": 8, "c": 13},
            {"a": 8, "b": 13, "c": 21},
            {"a": 0, "b": 0, "c": 1, "marks": pytest.mark.xfail},
        ],
    },
)
def test_something(a, b, c):
    assert a + b == c

Or more complex one:

from pytest_parametrize import parametrize

@parametrize(
    {
        "a=1": {"a": 1},
        "a=2": {"a": 2},
    }
)
@parametrize(
    {
        "b=1": {"b": 1},
        "b=2": {"b": 2},
    }
)
def test_parametrize__when_complex_structure(a: int, b: int):
    assert a * b > 0

Description

Decorator takes dict, which:

  • keys define names of the test cases, and
  • values define named arguments in dict manner (or list of such dicts), which are passed to the decorated test function.

Installation

pip

pip install pytest-parametrize

poetry

poetry add pytest-parametrize

Collaboration

Test & coverage

pytest -vvv tests --cov=pytest_parametrize

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_parametrize-1.5.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_parametrize-1.5.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest_parametrize-1.5.0.tar.gz.

File metadata

  • Download URL: pytest_parametrize-1.5.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure

File hashes

Hashes for pytest_parametrize-1.5.0.tar.gz
Algorithm Hash digest
SHA256 508bd6022b378e99b5bb7bb2c9bb3b17c966ba222880d80aa2c2198153d1cbed
MD5 920a4ee3b282a82dd759c98c739b83dc
BLAKE2b-256 be84fb597e2a42c34fd09445c2894ac3625a6d2187b832cd1cb5ccfc817f2a46

See more details on using hashes here.

File details

Details for the file pytest_parametrize-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_parametrize-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure

File hashes

Hashes for pytest_parametrize-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75639f6e12050bc247b56a0a2f437820034a80bf6f11bc32f72f73697ae1f24e
MD5 82711233824a1f33cb1f846c509a8081
BLAKE2b-256 9751cc3afaa11c3fd5c8bfc2e43c01a16c63e594a5a168c442763986dac21bec

See more details on using hashes here.

Supported by

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