deprecate the pytest.collect module

changelog

minimal unittest for collect module deprecations

\!fixup - changelog typo
This commit is contained in:
Ronny Pfannschmidt
2020-03-29 20:30:16 +02:00
parent ce429381a7
commit f1d51ba1f5
6 changed files with 54 additions and 30 deletions

View File

@@ -2,9 +2,9 @@
"""
pytest: unit and functional testing with Python.
"""
from . import collect
from _pytest import __version__
from _pytest.assertion import register_assert_rewrite
from _pytest.compat import _setup_collect_fakemodule
from _pytest.config import cmdline
from _pytest.config import ExitCode
from _pytest.config import hookimpl
@@ -46,7 +46,6 @@ from _pytest.warning_types import PytestUnhandledCoroutineWarning
from _pytest.warning_types import PytestUnknownMarkWarning
from _pytest.warning_types import PytestWarning
set_trace = __pytestPDB.set_trace
__all__ = [
@@ -55,6 +54,7 @@ __all__ = [
"approx",
"Class",
"cmdline",
"collect",
"Collector",
"deprecated_call",
"exit",
@@ -93,7 +93,3 @@ __all__ = [
"xfail",
"yield_fixture",
]
_setup_collect_fakemodule()
del _setup_collect_fakemodule

38
src/pytest/collect.py Normal file
View File

@@ -0,0 +1,38 @@
import sys
import warnings
from types import ModuleType
import pytest
from _pytest.deprecated import PYTEST_COLLECT_MODULE
COLLECT_FAKEMODULE_ATTRIBUTES = [
"Collector",
"Module",
"Function",
"Instance",
"Session",
"Item",
"Class",
"File",
"_fillfuncargs",
]
class FakeCollectModule(ModuleType):
def __init__(self):
super().__init__("pytest.collect")
self.__all__ = list(COLLECT_FAKEMODULE_ATTRIBUTES)
self.__pytest = pytest
def __dir__(self):
return dir(super()) + self.__all__
def __getattr__(self, name):
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()