Skip to content

Commit 9f5d73d

Browse files
Merge pull request #3735 from nicoddemus/deprecate-pytest-namespace
Deprecate pytest namespace
2 parents 8af78f4 + 8609f8d commit 9f5d73d

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

changelog/2639.removal.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``pytest_namespace`` has been deprecated.
2+
3+
See the documentation for ``pytest_namespace`` hook for suggestions on how to deal
4+
with this in plugins which use this functionality.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def main():
6969
# if _PYTEST_SETUP_SKIP_PLUGGY_DEP is set, skip installing pluggy;
7070
# used by tox.ini to test with pluggy master
7171
if "_PYTEST_SETUP_SKIP_PLUGGY_DEP" not in os.environ:
72-
install_requires.append("pluggy>=0.5,<0.8")
72+
install_requires.append("pluggy>=0.7")
7373
environment_marker_support_level = get_environment_marker_support_level()
7474
if environment_marker_support_level >= 2:
7575
install_requires.append('funcsigs;python_version<"3.0"')

src/_pytest/deprecated.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ class RemovedInPytest4Warning(DeprecationWarning):
7171
"because it affects the entire directory tree in a non-explicit way.\n"
7272
"Please move it to the top level conftest file instead."
7373
)
74+
75+
PYTEST_NAMESPACE = RemovedInPytest4Warning(
76+
"pytest_namespace is deprecated and will be removed soon"
77+
)

src/_pytest/hookspec.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """
22

33
from pluggy import HookspecMarker
4+
from .deprecated import PYTEST_NAMESPACE
5+
46

57
hookspec = HookspecMarker("pytest")
68

@@ -22,17 +24,29 @@ def pytest_addhooks(pluginmanager):
2224
"""
2325

2426

25-
@hookspec(historic=True)
27+
@hookspec(historic=True, warn_on_impl=PYTEST_NAMESPACE)
2628
def pytest_namespace():
2729
"""
28-
(**Deprecated**) this hook causes direct monkeypatching on pytest, its use is strongly discouraged
2930
return dict of name->object to be made globally available in
3031
the pytest namespace.
3132
3233
This hook is called at plugin registration time.
3334
3435
.. note::
3536
This hook is incompatible with ``hookwrapper=True``.
37+
38+
.. warning::
39+
This hook has been **deprecated** and will be removed in pytest 4.0.
40+
41+
Plugins whose users depend on the current namespace functionality should prepare to migrate to a
42+
namespace they actually own.
43+
44+
To support the migration its suggested to trigger ``DeprecationWarnings`` for objects they put into the
45+
pytest namespace.
46+
47+
An stopgap measure to avoid the warning is to monkeypatch the ``pytest`` module, but just as the
48+
``pytest_namespace`` hook this should be seen as a temporary measure to be removed in future versions after
49+
an appropriate transition period.
3650
"""
3751

3852

testing/test_pluginmanager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def test_namespace_early_from_import(self, testdir):
6666
result = testdir.runpython(p)
6767
assert result.ret == 0
6868

69+
@pytest.mark.filterwarnings("ignore:pytest_namespace is deprecated")
6970
def test_do_ext_namespace(self, testdir):
7071
testdir.makeconftest(
7172
"""

0 commit comments

Comments
 (0)