Skip to content

Commit d7e8eee

Browse files
authored
Merge pull request #2878 from RonnyPfannschmidt/collector-makeitem-deprecate
deprecate the public internal PyCollector.makeitem method
2 parents 7d43225 + d1aa553 commit d7e8eee

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

_pytest/deprecated.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ class RemovedInPytest4Warning(DeprecationWarning):
4040
" please use pytest.param(..., marks=...) instead.\n"
4141
"For more details, see: https://docs.pytest.org/en/latest/parametrize.html"
4242
)
43+
44+
COLLECTOR_MAKEITEM = RemovedInPytest4Warning(
45+
"pycollector makeitem was removed "
46+
"as it is an accidentially leaked internal api"
47+
)

_pytest/python.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import sys
77
import os
88
import collections
9+
import warnings
910
from textwrap import dedent
1011
from itertools import count
1112

13+
1214
import py
1315
import six
1416
from _pytest.mark import MarkerError
@@ -18,6 +20,7 @@
1820
import pluggy
1921
from _pytest import fixtures
2022
from _pytest import main
23+
from _pytest import deprecated
2124
from _pytest.compat import (
2225
isclass, isfunction, is_generator, ascii_escaped,
2326
REGEX_TYPE, STRING_TYPES, NoneType, NOTSET,
@@ -328,7 +331,7 @@ def collect(self):
328331
if name in seen:
329332
continue
330333
seen[name] = True
331-
res = self.makeitem(name, obj)
334+
res = self._makeitem(name, obj)
332335
if res is None:
333336
continue
334337
if not isinstance(res, list):
@@ -338,6 +341,10 @@ def collect(self):
338341
return l
339342

340343
def makeitem(self, name, obj):
344+
warnings.warn(deprecated.COLLECTOR_MAKEITEM, stacklevel=2)
345+
self._makeitem(name, obj)
346+
347+
def _makeitem(self, name, obj):
341348
# assert self.ihook.fspath == self.fspath, self
342349
return self.ihook.pytest_pycollect_makeitem(
343350
collector=self, name=name, obj=obj)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
from _pytest.python import PyCollector
4+
5+
6+
class PyCollectorMock(PyCollector):
7+
"""evil hack"""
8+
9+
def __init__(self):
10+
self.called = False
11+
12+
def _makeitem(self, *k):
13+
"""hack to disable the actual behaviour"""
14+
self.called = True
15+
16+
17+
def test_pycollector_makeitem_is_deprecated():
18+
19+
collector = PyCollectorMock()
20+
with pytest.deprecated_call():
21+
collector.makeitem('foo', 'bar')
22+
assert collector.called

0 commit comments

Comments
 (0)