diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 869c36bbc65..b28c64c2a70 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -91,9 +91,12 @@ def __call__(cls, *args, **kwargs): sig = inspect.signature(cls.__init__) bsig = sig.bind(cls, *args, **kwargs) if "parent" not in bsig.arguments: - warnings.warn( - NODE_USE_FROM_PARENT.format(name=cls.__name__), stacklevel=2 - ) + # XXX: handle DefinitionMock from tests. Could also go through + # _create instead (or get fixed?)? + if not getattr(cls, "_pytest_skip_ctor_check", False): + warnings.warn( + NODE_USE_FROM_PARENT.format(name=cls.__name__), stacklevel=2 + ) return super().__call__(*args, **kwargs) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index ae3856ba7b1..cf1fa82e7d4 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -24,6 +24,7 @@ def __init__(self, names): @attr.s class DefinitionMock(python.FunctionDefinition): + _pytest_skip_ctor_check = True obj = attr.ib() names = fixtures.getfuncargnames(func)