Skip to main content

A pytest plugin for testing logic that should work the same way across different types of functions: regular, async, and generator ones

Project description

Downloads Downloads Coverage Status Lines of code Hits-of-Code Test-Package Python versions PyPI version Checked with mypy Ruff DeepWiki

logo

If your code needs to work the same way with regular, asynchronous, and generator functions, you normally have to write three sets of nearly identical tests. With this library, you no longer need to do that — just use the special pytest fixture, which automatically generates the variants.

Usage

To use the fixture, install it via:

pip install transtests

The transformed fixture is now available. It returns a decorator that transforms the original function into one of three variants: a synchronous function, an asynchronous function, or a generator function:

from asyncio import run
from inspect import iscoroutinefunction, isgeneratorfunction

def test_something(transformed):
    @transformed
    def some_function(a, b):
        return a + b
    
    if iscoroutinefunction(some_function):
        assert run(some_function(1, 2)) == 3

    elif isgeneratorfunction(some_function):
        assert list(some_function(1, 2)) == [3]

    else:
        assert some_function(1, 2) == 3

↑ The test will be run three times automatically, once per variant.

This functionality is based on the transfunctions library, so you can use context managers from that library in the source function.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transtests-0.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

transtests-0.0.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file transtests-0.0.1.tar.gz.

File metadata

  • Download URL: transtests-0.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for transtests-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bbecddf65de246349daf0ca3bde254ada574eedd055936cea0e200d1cdbdff9e
MD5 8940cdae6912a25c72327c5448a65aa1
BLAKE2b-256 2c96ee2195a1ce43bf8a5e75eee01683e2c29ac1817f890a33b1880f9ba9a674

See more details on using hashes here.

Provenance

The following attestation bundles were made for transtests-0.0.1.tar.gz:

Publisher: release.yml on mutating/transtests

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transtests-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: transtests-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for transtests-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68774e7f7a7ca3a4ff99b18bd597e26f67b329396d51fc834a55c5c011477960
MD5 ed658cf997de6cf1844545155791c47f
BLAKE2b-256 c44b671bec37c6d1438336b0259f060fe073f67e06ea73de74b6cce658070d05

See more details on using hashes here.

Provenance

The following attestation bundles were made for transtests-0.0.1-py3-none-any.whl:

Publisher: release.yml on mutating/transtests

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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