Skip to content

Commit

Permalink
Merge pull request #2878 from RonnyPfannschmidt/collector-makeitem-de…
Browse files Browse the repository at this point in the history
…precate

deprecate the public internal PyCollector.makeitem method
  • Loading branch information
nicoddemus committed Nov 3, 2017
2 parents 7d43225 + d1aa553 commit d7e8eee
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions _pytest/deprecated.py
Expand Up @@ -40,3 +40,8 @@ class RemovedInPytest4Warning(DeprecationWarning):
" 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"
)
9 changes: 8 additions & 1 deletion _pytest/python.py
Expand Up @@ -6,9 +6,11 @@
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
Expand All @@ -18,6 +20,7 @@
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,
Expand Down Expand Up @@ -328,7 +331,7 @@ def collect(self):
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):
Expand All @@ -338,6 +341,10 @@ def collect(self):
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)
Expand Down
22 changes: 22 additions & 0 deletions 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

0 comments on commit d7e8eee

Please sign in to comment.