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.2.tar.gz (4.7 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.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for transtests-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f2cd6c20f3a6aafcacb7ebd4475352f1ad3453ebdc8d40c65a4dcb323379decc
MD5 b56bcd8cad985b9c9207643b6025ee52
BLAKE2b-256 e9253e29990ab8bff589b05f6f27c2c18abb8aa0295a4b48a6508a1a7f629a75

See more details on using hashes here.

Provenance

The following attestation bundles were made for transtests-0.0.2.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.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for transtests-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 47656ce9aedd40cce8398b4a39c2c0e3ce3dd157fb39e006fd758d971e56997f
MD5 4918061ecd37a4c6a64090d1c868baa3
BLAKE2b-256 7ba6777b14626033cc4bcfd67f4f7d8a082198c2f16d00548fa556e5674bffcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for transtests-0.0.2-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