summaryrefslogtreecommitdiff
path: root/src/pytest
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2020-03-29 20:30:16 +0200
committerRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2020-03-30 21:53:07 +0200
commitf1d51ba1f57619e71cdf787ff1507be59a057c73 (patch)
tree134574592a87d64a8c9b4298a963ad75e55d6edd /src/pytest
parentce429381a74cb8c6cdaa49efd63973d44ff07813 (diff)
downloadpytest-f1d51ba1f57619e71cdf787ff1507be59a057c73.tar.gz
deprecate the pytest.collect module
changelog minimal unittest for collect module deprecations \!fixup - changelog typo
Diffstat (limited to 'src/pytest')
-rw-r--r--src/pytest/__init__.py8
-rw-r--r--src/pytest/collect.py38
2 files changed, 40 insertions, 6 deletions
diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py
index 33bc3d0fb..5c93decc3 100644
--- a/src/pytest/__init__.py
+++ b/src/pytest/__init__.py
@@ -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
diff --git a/src/pytest/collect.py b/src/pytest/collect.py
new file mode 100644
index 000000000..73c9d35a0
--- /dev/null
+++ b/src/pytest/collect.py
@@ -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()