Skip to main content

A clean, modern, wrapper for pytest.mark.parametrize

Project description

pytest-case

workflow success codecov

PyPI - Downloads PyPI - Version

Usage examples:

import pytest
from typing import Tuple, Generator
from pytest_case import case


def add_test_cases() -> Generator[Tuple[int, int, int]]:
    yield (
        n
        for n in [
            (3, 3, 6),
            (3, 4, 7),
            (-1, 6, 5),
        ]
    )


@case("regular args", 4, 2, 2)
@case(
    "params as kwargs",
    a=2,
    b=2,
    expected=1,
)
@case('with expected fail', 1, 0, -1, mark=pytest.mark.xfail)
@case(add_test_cases())
def test__divide(a: int, b: int, expected: int) -> None:
    assert expected == a / b

Features

Default Arguments Values

@case("Check for Failure", val="Failure")
@case("Check for success", val="Success", sanity="Success")
def test__with_default(val: str, sanity: str = "Failure") -> None:
    assert sanity == val

Generator Case

from itertools import product
from pytest_case import case

@case(product(
    ("Chrome", "Firefox", "Safari"), 
    ("Windows", "macOS", "Linux")
))
def test__browser_os_compatibility(browser: str, operating_system: str) -> None:
    # Will generate cases:
    # ("Chrome", "Windows"), ("Chrome", "macOS"), ("Chrome", "Linux"), ("Firefox", "Windows"), ...
    pass

Using Fixtures

  • Using pytest built-in request fixture.
    def test__with_request_fixture(request: Any) -> None:
        fixture_value = request.getfixturevalue("fixture_name")
        ...
    
  • Using pytest-lazy-fixtures
    from pytest_case import case
    from pytest_lazy_fixtures import lf
    
    
    @case("Lazy Fixture Case", lf("fixture_name"))
    def test__with_lf_cases(fixture_val: Any) -> None
        ...
    

Project Roadmap:

These are the the predicted checkpoints for this project:

  • Test Arguments Default Values That would be cool!
  • Test Marks Marks that are currently supported by pytest, such as: xfail, skip, ...
  • Tests Cases Generators Provide a generator function to the case to automatically generate cases.
  • Use Fixtures Use fixtures in cases and tests
  • Tests Samples Generation Generate parameters to catch edge-cases, based on restrictions or datasets.

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_case-1.0.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

pytest_case-1.0.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_case-1.0.0.tar.gz.

File metadata

  • Download URL: pytest_case-1.0.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_case-1.0.0.tar.gz
Algorithm Hash digest
SHA256 12dfb557ad760ea517c429a20743d95d536a008a2a1c5e663e5dfcc25109bd8b
MD5 1dc706ee5f897fc23f7a1f4dc0bc1279
BLAKE2b-256 c07005e97274ffe052b886a2accf77ad00b01628b27fd34cebb7514655e8268f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_case-1.0.0.tar.gz:

Publisher: release.yml on eitanwass/pytest-case

Attestations:

File details

Details for the file pytest_case-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_case-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_case-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c0f25e6920f1a2a1cdc0cdb1066265666b18f370dc5c5a96013cd3692bae9cd
MD5 741361bd3b716c4e72f570d98169167c
BLAKE2b-256 f0a2ec8a13283d23c32cef21eae8b494fadf436dce131df6166bbdd9087a86ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_case-1.0.0-py3-none-any.whl:

Publisher: release.yml on eitanwass/pytest-case

Attestations:

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