Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support builtin pytest fixtures #1

Open
septatrix opened this issue Nov 24, 2024 · 1 comment · May be fixed by #2
Open

Support builtin pytest fixtures #1

septatrix opened this issue Nov 24, 2024 · 1 comment · May be fixed by #2

Comments

@septatrix
Copy link

It would be great if this plugin could re-export annotated version of the builtin pytest fixtures. Only problem is that they are currently not publicly exported...

@tristan
Copy link
Owner

tristan commented Nov 25, 2024

There is another problem that not all of them have unique types, or even pytest specific types.

e.g. capsys, capsysbinary, capfd and capfdbinary all share the CaptureFixture[...] type. So for these we would have to come up with a new unique name for an Annotated type to resolve it.

Also for things like tempdir that are typed as a pathlib.Path, I'd be hesitant to make a global resolution of that fixture based on the type alone.

If someone is in need of it right now, it can be done quite easily like so:

from typing import Annotated

from _pytest.capture import capsysbinary
from pytest import CaptureFixture

from pytest_annotated import Fixture

CapSysBinary = Annotated[CaptureFixture[bytes], Fixture(capsysbinary)]


def test_capsysbin(c: CapSysBinary):
    print("hello")
    captured = c.readouterr()
    assert captured.out == b"hello\n"

We could maybe add a bunch of these scoped to pytest_annotated (e.g. from pytest_annotated import CapSysBinary or from pytest_annotated import TempDir). If all the types can be mapped easily to a name that makes sense (without a lot of bikeshedding) I'd be happy to add it. I can't commit to doing it myself at this time though (I just don't have the time), happy to receive PRs though!

@septatrix septatrix linked a pull request Nov 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants