Skip to content

remove pytest namespace hook #4421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/4421.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the implementation of the pytest_namespace hook.
7 changes: 0 additions & 7 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,6 @@ def __init__(self, pluginmanager):
self.pluginmanager.register(self, "pytestconfig")
self._configured = False
self.invocation_dir = py.path.local()

def do_setns(dic):
import pytest

setns(pytest, dic)

self.hook.pytest_namespace.call_historic(do_setns, {})
self.hook.pytest_addoption.call_historic(kwargs=dict(parser=self._parser))

def add_cleanup(self, func):
Expand Down
3 changes: 0 additions & 3 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@
"Please move it to the top level conftest file instead."
)

PYTEST_NAMESPACE = RemovedInPytest4Warning(
"pytest_namespace is deprecated and will be removed soon"
)

PYTEST_ENSURETEMP = RemovedInPytest4Warning(
"pytest/tmpdir_factory.ensuretemp is deprecated, \n"
Expand Down
28 changes: 0 additions & 28 deletions src/_pytest/hookspec.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """
from pluggy import HookspecMarker

from .deprecated import PYTEST_NAMESPACE


hookspec = HookspecMarker("pytest")

Expand All @@ -24,32 +22,6 @@ def pytest_addhooks(pluginmanager):
"""


@hookspec(historic=True, warn_on_impl=PYTEST_NAMESPACE)
def pytest_namespace():
"""
return dict of name->object to be made globally available in
the pytest namespace.

This hook is called at plugin registration time.

.. note::
This hook is incompatible with ``hookwrapper=True``.

.. warning::
This hook has been **deprecated** and will be removed in pytest 4.0.

Plugins whose users depend on the current namespace functionality should prepare to migrate to a
namespace they actually own.

To support the migration it's suggested to trigger ``DeprecationWarnings`` for objects they put into the
pytest namespace.

A stopgap measure to avoid the warning is to monkeypatch the ``pytest`` module, but just as the
``pytest_namespace`` hook this should be seen as a temporary measure to be removed in future versions after
an appropriate transition period.
"""


@hookspec(historic=True)
def pytest_plugin_registered(plugin, manager):
""" a new pytest plugin got registered.
Expand Down
42 changes: 0 additions & 42 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,6 @@ def pytest_addhooks(pluginmanager):
assert res.ret != 0
res.stderr.fnmatch_lines(["*did not find*sys*"])

def test_namespace_early_from_import(self, testdir):
p = testdir.makepyfile(
"""
from pytest import Item
from pytest import Item as Item2
assert Item is Item2
"""
)
result = testdir.runpython(p)
assert result.ret == 0

@pytest.mark.filterwarnings("ignore:pytest_namespace is deprecated")
def test_do_ext_namespace(self, testdir):
testdir.makeconftest(
"""
def pytest_namespace():
return {'hello': 'world'}
"""
)
p = testdir.makepyfile(
"""
from pytest import hello
import pytest
def test_hello():
assert hello == "world"
assert 'hello' in pytest.__all__
"""
)
reprec = testdir.inline_run(p)
reprec.assertoutcome(passed=1)

def test_do_option_postinitialize(self, testdir):
config = testdir.parseconfigure()
assert not hasattr(config.option, "test123")
Expand Down Expand Up @@ -190,17 +159,6 @@ def pytest_testhook():
assert "deprecated" in warnings[-1]


def test_namespace_has_default_and_env_plugins(testdir):
p = testdir.makepyfile(
"""
import pytest
pytest.mark
"""
)
result = testdir.runpython(p)
assert result.ret == 0


def test_default_markers(testdir):
result = testdir.runpytest("--markers")
result.stdout.fnmatch_lines(["*tryfirst*first*", "*trylast*last*"])
Expand Down