Skip to content

Commit

Permalink
Remove support for using "Class" objects to customize nodes in collec…
Browse files Browse the repository at this point in the history
…tors

Fix #4530
  • Loading branch information
nicoddemus committed Dec 11, 2018
1 parent bb363c8 commit 883fcd7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 38 deletions.
3 changes: 3 additions & 0 deletions changelog/4530.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Removed support for using objects named ``"Class"`` as a way to customize the type of nodes that are collected in ``Collector``.

See our `docs <https://docs.pytest.org/en/latest/deprecations.html#using-class-in-custom-collectors>`__ on information on how to update your code.
22 changes: 12 additions & 10 deletions doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,7 @@ Becomes:
exec("assert(1, 2)") # exec is used to avoid a top-level warning
Using ``Class`` in custom Collectors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 3.9

Using objects named ``"Class"`` as a way to customize the type of nodes that are collected in ``Collector``
subclasses has been deprecated. Users instead should use ``pytest_pycollect_makeitem`` to customize node types during
collection.

This issue should affect only advanced plugins who create new collection types, so if you see this warning
message please contact the authors so they can change the code.
``Config.warn`` and ``Node.warn``
Expand Down Expand Up @@ -280,6 +270,18 @@ Removed Features
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
an appropriate period of deprecation has passed.

Using ``Class`` in custom Collectors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*Removed in version 4.0.*

Using objects named ``"Class"`` as a way to customize the type of nodes that are collected in ``Collector``
subclasses has been deprecated. Users instead should use ``pytest_pycollect_makeitem`` to customize node types during
collection.

This issue should affect only advanced plugins who create new collection types, so if you see this warning
message please contact the authors so they can change the code.

Metafunc.addcall
~~~~~~~~~~~~~~~~

Expand Down
3 changes: 0 additions & 3 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@
'"record_xml_property" is now deprecated.'
)

COLLECTOR_MAKEITEM = RemovedInPytest4Warning(
"pycollector makeitem was removed as it is an accidentially leaked internal api"
)

PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning(
"Defining pytest_plugins in a non-top-level conftest is deprecated, "
Expand Down
4 changes: 0 additions & 4 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,6 @@ def collect(self):
values.sort(key=lambda item: item.reportinfo()[:2])
return values

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
20 changes: 0 additions & 20 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,26 +268,6 @@ def fix():
assert fix() == 1


def test_pycollector_makeitem_is_deprecated():
from _pytest.python import PyCollector
from _pytest.warning_types import RemovedInPytest4Warning

class PyCollectorMock(PyCollector):
"""evil hack"""

def __init__(self):
self.called = False

def _makeitem(self, *k):
"""hack to disable the actual behaviour"""
self.called = True

collector = PyCollectorMock()
with pytest.warns(RemovedInPytest4Warning):
collector.makeitem("foo", "bar")
assert collector.called


def test_fixture_named_request(testdir):
testdir.copy_example()
result = testdir.runpytest()
Expand Down
2 changes: 1 addition & 1 deletion testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def test_makeitem_non_underscore(self, testdir, monkeypatch):
modcol = testdir.getmodulecol("def _hello(): pass")
values = []
monkeypatch.setattr(
pytest.Module, "makeitem", lambda self, name, obj: values.append(name)
pytest.Module, "_makeitem", lambda self, name, obj: values.append(name)
)
values = modcol.collect()
assert "_hello" not in values
Expand Down

0 comments on commit 883fcd7

Please sign in to comment.