Skip to content

Commit

Permalink
Export FixtureDef
Browse files Browse the repository at this point in the history
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 pytest-dev#7469.
  • Loading branch information
bluetech committed Jul 15, 2023
1 parent 9d0ddb4 commit fb55615
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/7469.feature.rst
@@ -0,0 +1 @@
:class:`~pytest.FixtureDef` is now exported as ``pytest.FixtureDef`` for typing purposes.
2 changes: 1 addition & 1 deletion doc/en/reference/reference.rst
Expand Up @@ -910,7 +910,7 @@ ExitCode
FixtureDef
~~~~~~~~~~

.. autoclass:: _pytest.fixtures.FixtureDef()
.. autoclass:: pytest.FixtureDef()
:members:
:show-inheritance:

Expand Down
11 changes: 10 additions & 1 deletion src/_pytest/fixtures.py
Expand Up @@ -216,6 +216,7 @@ def add_funcarg_pseudo_fixture_def(
params=valuelist,
unittest=False,
ids=None,
_ispytest=True,
)
arg2fixturedefs[argname] = [fixturedef]
if name2pseudofixturedef is not None:
Expand Down Expand Up @@ -974,7 +975,11 @@ def _eval_scope_callable(

@final
class FixtureDef(Generic[FixtureValue]):
"""A container for a fixture definition."""
"""A container for a fixture definition.
Note: At this time, only explicitly documented fields and methods are
considered public stable API.
"""

def __init__(
self,
Expand All @@ -988,7 +993,10 @@ def __init__(
ids: Optional[
Union[Tuple[Optional[object], ...], Callable[[Any], Optional[object]]]
] = None,
*,
_ispytest: bool = False,
) -> None:
check_ispytest(_ispytest)
self._fixturemanager = fixturemanager
# The "base" node ID for the fixture.
#
Expand Down Expand Up @@ -1708,6 +1716,7 @@ def parsefactories( # noqa: F811
params=marker.params,
unittest=unittest,
ids=marker.ids,
_ispytest=True,
)

faclist = self._arg2fixturedefs.setdefault(name, [])
Expand Down
2 changes: 2 additions & 0 deletions src/pytest/__init__.py
Expand Up @@ -20,6 +20,7 @@
from _pytest.debugging import pytestPDB as __pytestPDB
from _pytest.doctest import DoctestItem
from _pytest.fixtures import fixture
from _pytest.fixtures import FixtureDef
from _pytest.fixtures import FixtureLookupError
from _pytest.fixtures import FixtureRequest
from _pytest.fixtures import yield_fixture
Expand Down Expand Up @@ -102,6 +103,7 @@
"fail",
"File",
"fixture",
"FixtureDef",
"FixtureLookupError",
"FixtureRequest",
"freeze_includes",
Expand Down

0 comments on commit fb55615

Please sign in to comment.