From 821f9a94d8e5f8328abb43277781d29c03fa1b05 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 27 Oct 2017 18:34:52 +0200 Subject: [PATCH 1/3] deprecate the public internal PyCollector.makeitem method --- _pytest/deprecated.py | 5 +++++ _pytest/python.py | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/_pytest/deprecated.py b/_pytest/deprecated.py index 38e949677..e9231f221 100644 --- a/_pytest/deprecated.py +++ b/_pytest/deprecated.py @@ -40,3 +40,8 @@ MARK_PARAMETERSET_UNPACKING = RemovedInPytest4Warning( " please use pytest.param(..., marks=...) instead.\n" "For more details, see: https://docs.pytest.org/en/latest/parametrize.html" ) + +COLLECTOR_MAKEITEM = RemovedInPytest4Warning( + "pycollector makeitem was removed " + "as it is an accidentially leaked internal api" +) \ No newline at end of file diff --git a/_pytest/python.py b/_pytest/python.py index c47422937..4a0501bf4 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -6,9 +6,11 @@ import inspect import sys import os import collections +import warnings from textwrap import dedent from itertools import count + import py import six from _pytest.mark import MarkerError @@ -18,6 +20,7 @@ import _pytest import pluggy from _pytest import fixtures from _pytest import main +from _pytest import deprecated from _pytest.compat import ( isclass, isfunction, is_generator, ascii_escaped, REGEX_TYPE, STRING_TYPES, NoneType, NOTSET, @@ -328,7 +331,7 @@ class PyCollector(PyobjMixin, main.Collector): if name in seen: continue seen[name] = True - res = self.makeitem(name, obj) + res = self._makeitem(name, obj) if res is None: continue if not isinstance(res, list): @@ -338,6 +341,10 @@ class PyCollector(PyobjMixin, main.Collector): return l def makeitem(self, name, obj): + warnings.warn(deprecated.COLLECTOR_MAKEITEM, stacklevel=2) + self._makeitem(name, obj) + + def _makeitem(self, name, obj): # assert self.ihook.fspath == self.fspath, self return self.ihook.pytest_pycollect_makeitem( collector=self, name=name, obj=obj) From 766de67392dda354fd37023f219dd71a4252efce Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 27 Oct 2017 18:42:46 -0200 Subject: [PATCH 2/3] Fix linting error in deprecated.py --- _pytest/deprecated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/deprecated.py b/_pytest/deprecated.py index e9231f221..910510b01 100644 --- a/_pytest/deprecated.py +++ b/_pytest/deprecated.py @@ -44,4 +44,4 @@ MARK_PARAMETERSET_UNPACKING = RemovedInPytest4Warning( COLLECTOR_MAKEITEM = RemovedInPytest4Warning( "pycollector makeitem was removed " "as it is an accidentially leaked internal api" -) \ No newline at end of file +) From d1aa553f739e91cd470eea23042b6c8bcebe9b6f Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Mon, 30 Oct 2017 16:44:49 +0100 Subject: [PATCH 3/3] add mocked integrationtest for the deprecationwarning of makeitem --- testing/python/test_deprecations.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 testing/python/test_deprecations.py diff --git a/testing/python/test_deprecations.py b/testing/python/test_deprecations.py new file mode 100644 index 000000000..5001f765f --- /dev/null +++ b/testing/python/test_deprecations.py @@ -0,0 +1,22 @@ +import pytest + +from _pytest.python import PyCollector + + +class PyCollectorMock(PyCollector): + """evil hack""" + + def __init__(self): + self.called = False + + def _makeitem(self, *k): + """hack to disable the actual behaviour""" + self.called = True + + +def test_pycollector_makeitem_is_deprecated(): + + collector = PyCollectorMock() + with pytest.deprecated_call(): + collector.makeitem('foo', 'bar') + assert collector.called