Skip to content

Commit e8aa906

Browse files
sadra-barikbinbluetech
authored andcommitted
fixtures: move _get_direct_parametrize_args to a standalone function
So it can be used independently of the FixtureManager.
1 parent 12054a4 commit e8aa906

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ Ross Lawley
327327
Ruaridh Williamson
328328
Russel Winder
329329
Ryan Wooden
330+
Sadra Barikbin
330331
Saiprasad Kale
331332
Samuel Colvin
332333
Samuel Dion-Girardeau

src/_pytest/fixtures.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,26 @@ def pytest_addoption(parser: Parser) -> None:
14041404
)
14051405

14061406

1407+
def _get_direct_parametrize_args(node: nodes.Node) -> List[str]:
1408+
"""Return all direct parametrization arguments of a node, so we don't
1409+
mistake them for fixtures.
1410+
1411+
Check https://github.com/pytest-dev/pytest/issues/5036.
1412+
1413+
These things are done later as well when dealing with parametrization
1414+
so this could be improved.
1415+
"""
1416+
parametrize_argnames: List[str] = []
1417+
for marker in node.iter_markers(name="parametrize"):
1418+
if not marker.kwargs.get("indirect", False):
1419+
p_argnames, _ = ParameterSet._parse_parametrize_args(
1420+
*marker.args, **marker.kwargs
1421+
)
1422+
parametrize_argnames.extend(p_argnames)
1423+
1424+
return parametrize_argnames
1425+
1426+
14071427
class FixtureManager:
14081428
"""pytest fixture definitions and information is stored and managed
14091429
from this class.
@@ -1453,25 +1473,6 @@ def __init__(self, session: "Session") -> None:
14531473
}
14541474
session.config.pluginmanager.register(self, "funcmanage")
14551475

1456-
def _get_direct_parametrize_args(self, node: nodes.Node) -> List[str]:
1457-
"""Return all direct parametrization arguments of a node, so we don't
1458-
mistake them for fixtures.
1459-
1460-
Check https://github.com/pytest-dev/pytest/issues/5036.
1461-
1462-
These things are done later as well when dealing with parametrization
1463-
so this could be improved.
1464-
"""
1465-
parametrize_argnames: List[str] = []
1466-
for marker in node.iter_markers(name="parametrize"):
1467-
if not marker.kwargs.get("indirect", False):
1468-
p_argnames, _ = ParameterSet._parse_parametrize_args(
1469-
*marker.args, **marker.kwargs
1470-
)
1471-
parametrize_argnames.extend(p_argnames)
1472-
1473-
return parametrize_argnames
1474-
14751476
def getfixtureinfo(
14761477
self,
14771478
node: nodes.Item,
@@ -1503,7 +1504,7 @@ def getfixtureinfo(
15031504
)
15041505
initialnames = usefixtures + argnames
15051506
initialnames, names_closure, arg2fixturedefs = self.getfixtureclosure(
1506-
initialnames, node, ignore_args=self._get_direct_parametrize_args(node)
1507+
initialnames, node, ignore_args=_get_direct_parametrize_args(node)
15071508
)
15081509
return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)
15091510

0 commit comments

Comments
 (0)