Skip to content

Commit ba17363

Browse files
remove pytest namespace hook
1 parent 62967b3 commit ba17363

File tree

5 files changed

+1
-80
lines changed

5 files changed

+1
-80
lines changed

changelog/4421.removal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the implementation of the pytest_namespace hook.

src/_pytest/config/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,6 @@ def __init__(self, pluginmanager):
610610
self.pluginmanager.register(self, "pytestconfig")
611611
self._configured = False
612612
self.invocation_dir = py.path.local()
613-
614-
def do_setns(dic):
615-
import pytest
616-
617-
setns(pytest, dic)
618-
619-
self.hook.pytest_namespace.call_historic(do_setns, {})
620613
self.hook.pytest_addoption.call_historic(kwargs=dict(parser=self._parser))
621614

622615
def add_cleanup(self, func):

src/_pytest/deprecated.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@
113113
"Please move it to the top level conftest file instead."
114114
)
115115

116-
PYTEST_NAMESPACE = RemovedInPytest4Warning(
117-
"pytest_namespace is deprecated and will be removed soon"
118-
)
119116

120117
PYTEST_ENSURETEMP = RemovedInPytest4Warning(
121118
"pytest/tmpdir_factory.ensuretemp is deprecated, \n"

src/_pytest/hookspec.py

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

4-
from .deprecated import PYTEST_NAMESPACE
5-
64

75
hookspec = HookspecMarker("pytest")
86

@@ -24,32 +22,6 @@ def pytest_addhooks(pluginmanager):
2422
"""
2523

2624

27-
@hookspec(historic=True, warn_on_impl=PYTEST_NAMESPACE)
28-
def pytest_namespace():
29-
"""
30-
return dict of name->object to be made globally available in
31-
the pytest namespace.
32-
33-
This hook is called at plugin registration time.
34-
35-
.. note::
36-
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 it's suggested to trigger ``DeprecationWarnings`` for objects they put into the
45-
pytest namespace.
46-
47-
A 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.
50-
"""
51-
52-
5325
@hookspec(historic=True)
5426
def pytest_plugin_registered(plugin, manager):
5527
""" a new pytest plugin got registered.

testing/test_pluginmanager.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,6 @@ def pytest_addhooks(pluginmanager):
5959
assert res.ret != 0
6060
res.stderr.fnmatch_lines(["*did not find*sys*"])
6161

62-
def test_namespace_early_from_import(self, testdir):
63-
p = testdir.makepyfile(
64-
"""
65-
from pytest import Item
66-
from pytest import Item as Item2
67-
assert Item is Item2
68-
"""
69-
)
70-
result = testdir.runpython(p)
71-
assert result.ret == 0
72-
73-
@pytest.mark.filterwarnings("ignore:pytest_namespace is deprecated")
74-
def test_do_ext_namespace(self, testdir):
75-
testdir.makeconftest(
76-
"""
77-
def pytest_namespace():
78-
return {'hello': 'world'}
79-
"""
80-
)
81-
p = testdir.makepyfile(
82-
"""
83-
from pytest import hello
84-
import pytest
85-
def test_hello():
86-
assert hello == "world"
87-
assert 'hello' in pytest.__all__
88-
"""
89-
)
90-
reprec = testdir.inline_run(p)
91-
reprec.assertoutcome(passed=1)
92-
9362
def test_do_option_postinitialize(self, testdir):
9463
config = testdir.parseconfigure()
9564
assert not hasattr(config.option, "test123")
@@ -190,17 +159,6 @@ def pytest_testhook():
190159
assert "deprecated" in warnings[-1]
191160

192161

193-
def test_namespace_has_default_and_env_plugins(testdir):
194-
p = testdir.makepyfile(
195-
"""
196-
import pytest
197-
pytest.mark
198-
"""
199-
)
200-
result = testdir.runpython(p)
201-
assert result.ret == 0
202-
203-
204162
def test_default_markers(testdir):
205163
result = testdir.runpytest("--markers")
206164
result.stdout.fnmatch_lines(["*tryfirst*first*", "*trylast*last*"])

0 commit comments

Comments
 (0)