Skip to content

feat: expose FixtureFunctionDefinition for typing - #14862

Open
teddygood wants to merge 1 commit into
pytest-dev:mainfrom
teddygood:expose-fixture-function-definition
Open

feat: expose FixtureFunctionDefinition for typing#14862
teddygood wants to merge 1 commit into
pytest-dev:mainfrom
teddygood:expose-fixture-function-definition

Conversation

@teddygood

@teddygood teddygood commented Aug 12, 2026

Copy link
Copy Markdown

Closes #14853

Summary

pytest.fixture returns a FixtureFunctionDefinition, but users previously had to import this type from the private _pytest.fixtures module when annotating fixture factories.

This change exports the existing class as pytest.FixtureFunctionDefinition and adds it to the API reference. It does not introduce a new class or change fixture behavior at runtime. The supported public surface is limited to its use in type annotations. Direct instantiation, subclassing, and its attributes remain outside the public API.

A typing check covers fixture factories returning the public type. The obsolete Sphinx cross-reference exception is also removed now that the type has a public documentation target.

Co-authored-by: OpenAI Codex <noreply@openai.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 12, 2026
Comment thread src/_pytest/fixtures.py
@@ -1454,6 +1454,12 @@ def __call__(self, function: FixtureFunction) -> FixtureFunctionDefinition:

# TODO: paramspec/return type annotation tracking and storing
class FixtureFunctionDefinition:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pytest-dev/core if we expose this - do we want to make the return type a generic?

Comment thread src/_pytest/fixtures.py
"""The type of a fixture function after decoration by :func:`pytest.fixture`.
This type is public for type annotations. It should not be instantiated
or subclassed by users, and its attributes are not part of the public API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be marked @final?

@teddygood teddygood Aug 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I had considered whether @final was necessary, but you’re right. I’ll add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose FixtureFunctionDefinition as part of the public API

3 participants