Skip to content

Commit b03896b

Browse files
RonnyPfannschmidtCursor AIclaude
committed
deprecate: add PytestRemovedIn10Warning for baseid/nodeid string parameters
Add deprecation warnings for using string-based fixture scoping: - FixtureDef baseid parameter: use node parameter instead - _register_fixture nodeid parameter: use node parameter instead - parsefactories nodeid string: use holder/node API instead The warnings only trigger when a non-empty nodeid string is passed without a node. Global plugins (nodeid=None) and synthetic fixtures (baseid='') do not trigger warnings. These will be removed in pytest 10, completing the migration to node-based fixture scoping. Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Anthropic Claude Opus 4 <claude@anthropic.com>
1 parent 4b82e95 commit b03896b

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/_pytest/fixtures.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
from _pytest.scope import _ScopeName
6868
from _pytest.scope import HIGH_SCOPES
6969
from _pytest.scope import Scope
70+
from _pytest.warning_types import PytestRemovedIn10Warning
7071
from _pytest.warning_types import PytestWarning
7172

7273

@@ -975,6 +976,15 @@ def __init__(
975976
node: nodes.Node | None = None,
976977
) -> None:
977978
check_ispytest(_ispytest)
979+
# Emit deprecation warning if baseid string is used when node could be provided.
980+
# baseid=None (global plugins) and baseid="" (synthetic fixtures) are fine.
981+
if baseid and node is None:
982+
warnings.warn(
983+
"Passing baseid to FixtureDef is deprecated. "
984+
"Pass node instead for fixture scoping.",
985+
PytestRemovedIn10Warning,
986+
stacklevel=2,
987+
)
978988
# The node where this fixture was defined, if available.
979989
# Used for node-based matching which is more robust than string matching.
980990
self.node: Final = node
@@ -1799,7 +1809,7 @@ def _register_fixture(
17991809
:param func:
18001810
The fixture's implementation function.
18011811
:param nodeid:
1802-
The visibility of the fixture (legacy, prefer node).
1812+
The visibility of the fixture (deprecated, use node instead).
18031813
The fixture will be available to the node with this nodeid and
18041814
its children in the collection tree. None means global visibility.
18051815
:param node:
@@ -1814,6 +1824,15 @@ def _register_fixture(
18141824
:param autouse:
18151825
Whether this is an autouse fixture.
18161826
"""
1827+
# Emit deprecation warning if nodeid string is used when node could be provided.
1828+
# nodeid=None (global plugins) is fine.
1829+
if nodeid and node is None:
1830+
warnings.warn(
1831+
"Passing nodeid to _register_fixture is deprecated. "
1832+
"Pass node instead for fixture scoping.",
1833+
PytestRemovedIn10Warning,
1834+
stacklevel=2,
1835+
)
18171836
fixture_def = FixtureDef(
18181837
config=self.config,
18191838
baseid=nodeid if node is None else None,
@@ -1901,6 +1920,14 @@ def parsefactories(
19011920
raise TypeError("parsefactories() requires holder or node_or_obj")
19021921
elif nodeid is not NOTSET:
19031922
# Legacy: parsefactories(obj, nodeid) - string-based scoping only
1923+
# Only warn if a non-None nodeid string is passed (None means global plugin)
1924+
if nodeid is not None:
1925+
warnings.warn(
1926+
"Passing nodeid string to parsefactories is deprecated. "
1927+
"Use parsefactories(holder=obj, node=node) instead.",
1928+
PytestRemovedIn10Warning,
1929+
stacklevel=2,
1930+
)
19041931
holderobj = node_or_obj
19051932
effective_nodeid = nodeid
19061933
else:

0 commit comments

Comments
 (0)