Pytest plugin to allow use of Annotated in tests to resolve fixtures
Project description
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
Annotatedfunction arguments in fixtures as well. - Figure out if there's a way to do this without using so many
_privateparts of pytest!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_annotated-0.1.1.tar.gz.
File metadata
- Download URL: pytest_annotated-0.1.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8f9e5d249fbfbec1ca025ec943665fc76e130706644263e0e5338971e65ccbe
|
|
| MD5 |
d59ce724eb871f81aace5edccdb66c98
|
|
| BLAKE2b-256 |
dd786ac3c24cff0bb8c1c2d843d13728bf8363b8580682b75f01604684ddfecc
|
File details
Details for the file pytest_annotated-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pytest_annotated-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb063f232c14354f621e46bca825e6a9f51cd0da6d35a52c4c3fd1ea21b4d750
|
|
| MD5 |
e248c06ad05b2f16e2a0294a200b6637
|
|
| BLAKE2b-256 |
df79405867c86540babc260836a46e59b394b7a5b4dfdefeb3287fa02607c8ac
|