Merge pull request #11253 from bluetech/11243-cherry-picks

11243 cherry picks
This commit is contained in:
Ran Benita 2023-07-27 10:19:40 +03:00 committed by GitHub
commit 448563caaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 23 deletions

View File

@ -327,6 +327,7 @@ Ross Lawley
Ruaridh Williamson Ruaridh Williamson
Russel Winder Russel Winder
Ryan Wooden Ryan Wooden
Sadra Barikbin
Saiprasad Kale Saiprasad Kale
Samuel Colvin Samuel Colvin
Samuel Dion-Girardeau Samuel Dion-Girardeau

View File

@ -353,9 +353,9 @@ def _get_legacy_hook_marks(
if TYPE_CHECKING: if TYPE_CHECKING:
# abuse typeguard from importlib to avoid massive method type union thats lacking a alias # abuse typeguard from importlib to avoid massive method type union thats lacking a alias
assert inspect.isroutine(method) assert inspect.isroutine(method)
known_marks: set[str] = {m.name for m in getattr(method, "pytestmark", [])} known_marks: Set[str] = {m.name for m in getattr(method, "pytestmark", [])}
must_warn: list[str] = [] must_warn: List[str] = []
opts: dict[str, bool] = {} opts: Dict[str, bool] = {}
for opt_name in opt_names: for opt_name in opt_names:
opt_attr = getattr(method, opt_name, AttributeError) opt_attr = getattr(method, opt_name, AttributeError)
if opt_attr is not AttributeError: if opt_attr is not AttributeError:

View File

@ -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: class FixtureManager:
"""pytest fixture definitions and information is stored and managed """pytest fixture definitions and information is stored and managed
from this class. from this class.
@ -1453,25 +1473,6 @@ class FixtureManager:
} }
session.config.pluginmanager.register(self, "funcmanage") 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( def getfixtureinfo(
self, self,
node: nodes.Item, node: nodes.Item,
@ -1503,7 +1504,7 @@ class FixtureManager:
) )
initialnames = usefixtures + argnames initialnames = usefixtures + argnames
initialnames, names_closure, arg2fixturedefs = self.getfixtureclosure( 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) return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)