Skip to main content

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.

Metadata

Release files for pytest-case 1.0.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-case 1.0.0
File Size Uploaded
pytest_case-1.0.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-case 1.0.0
File Interpreter ABI Platform
pytest_case-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.8 kB

Release files / pytest_case-1.0.0.tar.gz

Download URL pytest_case-1.0.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
12dfb557ad760ea517c429a20743d95d536a008a2a1c5e663e5dfcc25109bd8b
BLAKE2b-256 checksum
How to use checksums
c07005e97274ffe052b886a2accf77ad00b01628b27fd34cebb7514655e8268f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2024.

Transparency log

Release files / pytest_case-1.0.0-py3-none-any.whl

Download URL pytest_case-1.0.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c0f25e6920f1a2a1cdc0cdb1066265666b18f370dc5c5a96013cd3692bae9cd
BLAKE2b-256 checksum
How to use checksums
f0a2ec8a13283d23c32cef21eae8b494fadf436dce131df6166bbdd9087a86ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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