Remove deprecated `pytest.collect` module

This commit is contained in:
Ran Benita 2021-12-07 22:14:55 +02:00
parent 4a45a5e983
commit 0f39f11d88
5 changed files with 11 additions and 62 deletions

View File

@ -250,15 +250,6 @@ The ``yield_fixture`` function/decorator
It has been so for a very long time, so can be search/replaced safely. It has been so for a very long time, so can be search/replaced safely.
The ``pytest.collect`` module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 6.0
The ``pytest.collect`` module is no longer part of the public API, all its names
should now be imported from ``pytest`` directly instead.
Removed Features Removed Features
---------------- ----------------
@ -266,6 +257,17 @@ As stated in our :ref:`backwards-compatibility` policy, deprecated features are
an appropriate period of deprecation has passed. an appropriate period of deprecation has passed.
The ``pytest.collect`` module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 6.0
.. versionremoved:: 7.0
The ``pytest.collect`` module is no longer part of the public API, all its names
should now be imported from ``pytest`` directly instead.
The ``pytest_warning_captured`` hook The ``pytest_warning_captured`` hook
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -11,7 +11,6 @@ in case of warnings which need to format their messages.
from warnings import warn from warnings import warn
from _pytest.warning_types import PytestDeprecationWarning from _pytest.warning_types import PytestDeprecationWarning
from _pytest.warning_types import PytestRemovedIn7Warning
from _pytest.warning_types import PytestRemovedIn8Warning from _pytest.warning_types import PytestRemovedIn8Warning
from _pytest.warning_types import UnformattedWarning from _pytest.warning_types import UnformattedWarning
@ -24,12 +23,6 @@ DEPRECATED_EXTERNAL_PLUGINS = {
} }
PYTEST_COLLECT_MODULE = UnformattedWarning(
PytestRemovedIn7Warning,
"pytest.collect.{name} was moved to pytest.{name}\n"
"Please update to the new name.",
)
# This can be* removed pytest 8, but it's harmless and common, so no rush to remove. # This can be* removed pytest 8, but it's harmless and common, so no rush to remove.
# * If you're in the future: "could have been". # * If you're in the future: "could have been".
YIELD_FIXTURE = PytestDeprecationWarning( YIELD_FIXTURE = PytestDeprecationWarning(

View File

@ -1,6 +1,5 @@
# PYTHON_ARGCOMPLETE_OK # PYTHON_ARGCOMPLETE_OK
"""pytest: unit and functional testing with Python.""" """pytest: unit and functional testing with Python."""
from . import collect
from _pytest import __version__ from _pytest import __version__
from _pytest import version_tuple from _pytest import version_tuple
from _pytest._code import ExceptionInfo from _pytest._code import ExceptionInfo
@ -86,7 +85,6 @@ __all__ = [
"CaptureFixture", "CaptureFixture",
"Class", "Class",
"cmdline", "cmdline",
"collect",
"Collector", "Collector",
"CollectReport", "CollectReport",
"Config", "Config",

View File

@ -1,37 +0,0 @@
import sys
import warnings
from types import ModuleType
from typing import Any
from typing import List
import pytest
from _pytest.deprecated import PYTEST_COLLECT_MODULE
COLLECT_FAKEMODULE_ATTRIBUTES = [
"Collector",
"Module",
"Function",
"Session",
"Item",
"Class",
"File",
]
class FakeCollectModule(ModuleType):
def __init__(self) -> None:
super().__init__("pytest.collect")
self.__all__ = list(COLLECT_FAKEMODULE_ATTRIBUTES)
self.__pytest = pytest
def __dir__(self) -> List[str]:
return dir(super()) + self.__all__
def __getattr__(self, name: str) -> Any:
if name not in self.__all__:
raise AttributeError(name)
warnings.warn(PYTEST_COLLECT_MODULE.format(name=name), stacklevel=2)
return getattr(pytest, name)
sys.modules["pytest.collect"] = FakeCollectModule()

View File

@ -10,13 +10,6 @@ from _pytest.pytester import Pytester
from pytest import PytestDeprecationWarning from pytest import PytestDeprecationWarning
@pytest.mark.parametrize("attribute", pytest.collect.__all__) # type: ignore
# false positive due to dynamic attribute
def test_pytest_collect_module_deprecated(attribute) -> None:
with pytest.warns(DeprecationWarning, match=attribute):
getattr(pytest.collect, attribute)
@pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS)) @pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS))
@pytest.mark.filterwarnings("default") @pytest.mark.filterwarnings("default")
def test_external_plugins_integrated(pytester: Pytester, plugin) -> None: def test_external_plugins_integrated(pytester: Pytester, plugin) -> None: