Skip to content

Commit

Permalink
fixtures: move _get_direct_parametrize_args to a standalone function
Browse files Browse the repository at this point in the history
So it can be used independently of the FixtureManager.
  • Loading branch information
sadra-barikbin authored and bluetech committed Jul 27, 2023
1 parent 12054a4 commit e8aa906
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ Ross Lawley
Ruaridh Williamson
Russel Winder
Ryan Wooden
Sadra Barikbin
Saiprasad Kale
Samuel Colvin
Samuel Dion-Girardeau
Expand Down
41 changes: 21 additions & 20 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,26 @@ def pytest_addoption(parser: Parser) -> None:
)


def _get_direct_parametrize_args(node: nodes.Node) -> List[str]:
"""Return all direct parametrization arguments of a node, so we don't
mistake them for fixtures.
Check https://github.com/pytest-dev/pytest/issues/5036.
These things are done later as well when dealing with parametrization
so this could be improved.
"""
parametrize_argnames: List[str] = []
for marker in node.iter_markers(name="parametrize"):
if not marker.kwargs.get("indirect", False):
p_argnames, _ = ParameterSet._parse_parametrize_args(
*marker.args, **marker.kwargs
)
parametrize_argnames.extend(p_argnames)

return parametrize_argnames


class FixtureManager:
"""pytest fixture definitions and information is stored and managed
from this class.
Expand Down Expand Up @@ -1453,25 +1473,6 @@ def __init__(self, session: "Session") -> None:
}
session.config.pluginmanager.register(self, "funcmanage")

def _get_direct_parametrize_args(self, node: nodes.Node) -> List[str]:
"""Return all direct parametrization arguments of a node, so we don't
mistake them for fixtures.
Check https://github.com/pytest-dev/pytest/issues/5036.
These things are done later as well when dealing with parametrization
so this could be improved.
"""
parametrize_argnames: List[str] = []
for marker in node.iter_markers(name="parametrize"):
if not marker.kwargs.get("indirect", False):
p_argnames, _ = ParameterSet._parse_parametrize_args(
*marker.args, **marker.kwargs
)
parametrize_argnames.extend(p_argnames)

return parametrize_argnames

def getfixtureinfo(
self,
node: nodes.Item,
Expand Down Expand Up @@ -1503,7 +1504,7 @@ def getfixtureinfo(
)
initialnames = usefixtures + argnames
initialnames, names_closure, arg2fixturedefs = self.getfixtureclosure(
initialnames, node, ignore_args=self._get_direct_parametrize_args(node)
initialnames, node, ignore_args=_get_direct_parametrize_args(node)
)
return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)

Expand Down

0 comments on commit e8aa906

Please sign in to comment.