Skip to main content

Pytest Annotated

A Pytest plugin to allow the use of Annotated to resolve fixtures, allowing test arguments to have different names to the fixture itself.

Usage:

Simple:

from typing import Annotated
from pytest_annotated import Fixture

class SomeThing:
    pass

@pytest.fixture
async def somefixture(someotherfixture) -> SomeThing:
    return SomeThing()

async def test_thing(st: Annotated[SomeThing, Fixture(somefixture)]):
    assert isinstance(st, SomeThing)

Aliased:

from typing import Annotated
from pytest_annotated import Fixture

class SomeThing:
    pass

@pytest.fixture
async def somefixture(someotherfixture) -> SomeThing:
    return SomeThing()

SomethingFixture = Annotated[SomeThing, Fixture(somefixture)]

async def test_thing(st: SomethingFixture):
    assert isinstance(st, SomeThing)

Registered Type:

Uses @pytest_annotated.fixture instead of @pytest.fixture to register the annotated return type of a fixture to always be resolved using that fixture.

from typing import Annotated
import pytest_annotated
from pytest_annotated import Fixture

class SomeThing:
    pass

@pytest_annotated.fixture
async def somefixture(someotherfixture) -> SomeThing:
    return SomeThing()

async def test_thing(st: SomeThing):
    assert isinstance(st, SomeThing)

TODO:

  • Support Annotated function arguments in fixtures as well.
  • Figure out if there's a way to do this without using so many _private parts of pytest!

Release files for pytest-annotated 0.1.1

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-annotated 0.1.1
File Size Uploaded
pytest_annotated-0.1.1.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-annotated 0.1.1
File Interpreter ABI Platform
pytest_annotated-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / pytest_annotated-0.1.1.tar.gz

Download URL pytest_annotated-0.1.1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a8f9e5d249fbfbec1ca025ec943665fc76e130706644263e0e5338971e65ccbe
BLAKE2b-256 checksum
How to use checksums
dd786ac3c24cff0bb8c1c2d843d13728bf8363b8580682b75f01604684ddfecc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.17

Release files / pytest_annotated-0.1.1-py3-none-any.whl

Download URL pytest_annotated-0.1.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb063f232c14354f621e46bca825e6a9f51cd0da6d35a52c4c3fd1ea21b4d750
BLAKE2b-256 checksum
How to use checksums
df79405867c86540babc260836a46e59b394b7a5b4dfdefeb3287fa02607c8ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.17

Release history Release notifications | RSS feed

This release

0.1.1 This release

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