From de91222d8eb119abf13076869333d55d129b69b8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 31 Jan 2020 19:26:50 +0100 Subject: [PATCH] tests: handle DefinitionMock --- src/_pytest/nodes.py | 9 ++++++--- testing/python/metafunc.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) 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)