Skip to content

Commit fb55615

Browse files
committed
Export FixtureDef
FixtureDef is used in the `pytest_fixture_setup` hook so needs to be public. However since its current internals are quite dubious (and not all marked with `_` prefix) I've added an explicit note that only documented fields/methods are considered public. Refs #7469.
1 parent 9d0ddb4 commit fb55615

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

changelog/7469.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:class:`~pytest.FixtureDef` is now exported as ``pytest.FixtureDef`` for typing purposes.

doc/en/reference/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ ExitCode
910910
FixtureDef
911911
~~~~~~~~~~
912912

913-
.. autoclass:: _pytest.fixtures.FixtureDef()
913+
.. autoclass:: pytest.FixtureDef()
914914
:members:
915915
:show-inheritance:
916916

src/_pytest/fixtures.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def add_funcarg_pseudo_fixture_def(
216216
params=valuelist,
217217
unittest=False,
218218
ids=None,
219+
_ispytest=True,
219220
)
220221
arg2fixturedefs[argname] = [fixturedef]
221222
if name2pseudofixturedef is not None:
@@ -974,7 +975,11 @@ def _eval_scope_callable(
974975

975976
@final
976977
class FixtureDef(Generic[FixtureValue]):
977-
"""A container for a fixture definition."""
978+
"""A container for a fixture definition.
979+
980+
Note: At this time, only explicitly documented fields and methods are
981+
considered public stable API.
982+
"""
978983

979984
def __init__(
980985
self,
@@ -988,7 +993,10 @@ def __init__(
988993
ids: Optional[
989994
Union[Tuple[Optional[object], ...], Callable[[Any], Optional[object]]]
990995
] = None,
996+
*,
997+
_ispytest: bool = False,
991998
) -> None:
999+
check_ispytest(_ispytest)
9921000
self._fixturemanager = fixturemanager
9931001
# The "base" node ID for the fixture.
9941002
#
@@ -1708,6 +1716,7 @@ def parsefactories( # noqa: F811
17081716
params=marker.params,
17091717
unittest=unittest,
17101718
ids=marker.ids,
1719+
_ispytest=True,
17111720
)
17121721

17131722
faclist = self._arg2fixturedefs.setdefault(name, [])

src/pytest/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from _pytest.debugging import pytestPDB as __pytestPDB
2121
from _pytest.doctest import DoctestItem
2222
from _pytest.fixtures import fixture
23+
from _pytest.fixtures import FixtureDef
2324
from _pytest.fixtures import FixtureLookupError
2425
from _pytest.fixtures import FixtureRequest
2526
from _pytest.fixtures import yield_fixture
@@ -102,6 +103,7 @@
102103
"fail",
103104
"File",
104105
"fixture",
106+
"FixtureDef",
105107
"FixtureLookupError",
106108
"FixtureRequest",
107109
"freeze_includes",

0 commit comments

Comments
 (0)