Merge pull request #2878 from RonnyPfannschmidt/collector-makeitem-deprecate
deprecate the public internal PyCollector.makeitem method
This commit is contained in:
commit
d7e8eeef56
|
@ -40,3 +40,8 @@ MARK_PARAMETERSET_UNPACKING = RemovedInPytest4Warning(
|
||||||
" please use pytest.param(..., marks=...) instead.\n"
|
" please use pytest.param(..., marks=...) instead.\n"
|
||||||
"For more details, see: https://docs.pytest.org/en/latest/parametrize.html"
|
"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"
|
||||||
|
)
|
||||||
|
|
|
@ -6,9 +6,11 @@ import inspect
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import collections
|
import collections
|
||||||
|
import warnings
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import six
|
import six
|
||||||
from _pytest.mark import MarkerError
|
from _pytest.mark import MarkerError
|
||||||
|
@ -18,6 +20,7 @@ import _pytest
|
||||||
import pluggy
|
import pluggy
|
||||||
from _pytest import fixtures
|
from _pytest import fixtures
|
||||||
from _pytest import main
|
from _pytest import main
|
||||||
|
from _pytest import deprecated
|
||||||
from _pytest.compat import (
|
from _pytest.compat import (
|
||||||
isclass, isfunction, is_generator, ascii_escaped,
|
isclass, isfunction, is_generator, ascii_escaped,
|
||||||
REGEX_TYPE, STRING_TYPES, NoneType, NOTSET,
|
REGEX_TYPE, STRING_TYPES, NoneType, NOTSET,
|
||||||
|
@ -328,7 +331,7 @@ class PyCollector(PyobjMixin, main.Collector):
|
||||||
if name in seen:
|
if name in seen:
|
||||||
continue
|
continue
|
||||||
seen[name] = True
|
seen[name] = True
|
||||||
res = self.makeitem(name, obj)
|
res = self._makeitem(name, obj)
|
||||||
if res is None:
|
if res is None:
|
||||||
continue
|
continue
|
||||||
if not isinstance(res, list):
|
if not isinstance(res, list):
|
||||||
|
@ -338,6 +341,10 @@ class PyCollector(PyobjMixin, main.Collector):
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def makeitem(self, name, obj):
|
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
|
# assert self.ihook.fspath == self.fspath, self
|
||||||
return self.ihook.pytest_pycollect_makeitem(
|
return self.ihook.pytest_pycollect_makeitem(
|
||||||
collector=self, name=name, obj=obj)
|
collector=self, name=name, obj=obj)
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue