Repository navigation
Expose FixtureFunctionDefinition as part of the public API #14853
Description
Activity
- addedgood first issueeasy issue that is friendly to new contributoreasy issue that is friendly to new contributortopic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectly
on Aug 11, 2026 I'd like to work on this. Could you assign it to me?
Hi! I’d be interested in working on this issue. My initial thought is to expose
FixtureFunctionDefinitionthrough a supported public API (possibly frompytest), along with the necessary typing/tests, rather than requiring users to import it from the private_pytest.fixturesmodule.I noticed it’s currently assigned to @teddygood, so I wanted to check whether they’re actively working on it. If not, I’d be happy to take this on and submit a PR.
Is this issue being worked upon? If so not, Please assign
There's an open PR by @teddygood from last week (you could check yourself on the side instead of asking).

@Gugilla-Aakash @siddy-stack Thanks for your interest. But I’m currently working on this, and there’s already an open PR for it.
Exposing this type has downsides: it locks an implementation detail, and increases the API surface. So my first inclination is to see how we can avoid exposing this.
@adamtheturtle use case seems valid, though I'd be interesting in a bit more details, I'm assuming the example given is not the real one.
But either case, the reason @adamtheturtle needs
FixtureFunctionDefinitionis becausepytest.fixturereturns it. But pytest core itself doesn't need this return type, it of course has no access to@pytest.fixturereturn value directly, it only sees it later during collection where of course it relies on the runtime type, not the static type.So perhaps we can undo the part of ecde993 that changes the return type of
pytest.fixture. It doesn't matter to pytest core (as explained above), nor to users (sinceFixtureFunctionDefinitionis private anyway, and they just need the type to be correct). In order for the types to match with the wrapper, we would need to revive the ParamSpec part from #13036.Reacted by Chanho LeeI think i want to introduce a opaque protocol for this
@bluetech I am the maintainer of vws-python-mock. It has a test suite where a bunch of tests are written once and run against a real web service, as well as a mock, and another mock. Each of these "backends" has its own setup and teardown, so I use fixtures. https://github.com/VWS-Python/vws-python-mock/blob/7ca1c36f03f38784389b4a02628cb095016ec25a/tests/backend_harness.py#L116-L159 is the function which wants this exposed.
@adamtheturtle Thanks, yeah that's perfectly reasonable.
I think i want to introduce a opaque protocol for this
Is there a benefit for this over returning the type of the input function with a generic? (To be clear, everything with
FixtureFunctionDefinitionwill remain the same, I'm talking only aboutpytest.fixturestatic type)The exposure we started with the _ispytest types locks concrete types in a lot of places
When i started to experiment with the ensemble apis I got a more concrete need to replace objects and being locked in
How does
_ispytestlock a concrete type? The intention (along with@final) was the opposite, to prevent constructing such that among other things it can be replaced entirely (including with a protocol if needed, though TBH I don't see a benefit for a protocol in such cases).the exported name is in type annotations and its a concrete type instead of a shape
makes creating fakes/stand-ins and/or wrappers a mess
Premature abstraction is the root of all evil :) Though there is nothing precluding replacing protected concrete types with ABCs or protocols.
But how does this apply to this case? The purpose of FixtureFunctionDefinition is to mark a function as a fixture definition for collection, and we use
isinstance(obj, FixtureFunctionDefinition)for this. What would a protocol replacement look like?Hi! I'd like to work on this issue as my first contribution to pytest.
Pierre-Sassoulas commented
on Sep 22, 2026 on Sep 22, 2026 · Hidden as outdatedshow commentMore actionsIs this issue being fixed? If not , please assign this to me

There doesn’t appear to be a public type that can be used to annotate the result of
pytest.fixture.For example, consider a factory which creates fixtures: