From ba17363d7585c3990d3f0c3796d747ff5f95433f Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Mon, 19 Nov 2018 14:02:37 +0100 Subject: [PATCH] remove pytest namespace hook --- changelog/4421.removal.rst | 1 + src/_pytest/config/__init__.py | 7 ------ src/_pytest/deprecated.py | 3 --- src/_pytest/hookspec.py | 28 ----------------------- testing/test_pluginmanager.py | 42 ---------------------------------- 5 files changed, 1 insertion(+), 80 deletions(-) create mode 100644 changelog/4421.removal.rst diff --git a/changelog/4421.removal.rst b/changelog/4421.removal.rst new file mode 100644 index 000000000..be0704faa --- /dev/null +++ b/changelog/4421.removal.rst @@ -0,0 +1 @@ +Remove the implementation of the pytest_namespace hook. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index ba11c8055..1d0cdffc9 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -610,13 +610,6 @@ class Config(object): 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): diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 8d7a17bca..a34366280 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -113,9 +113,6 @@ PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning( "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" diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 625f59e5a..0d9f039a1 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -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") @@ -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. diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 8e35290b7..64d05d383 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -59,37 +59,6 @@ class TestPytestPluginInteractions(object): 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") @@ -190,17 +159,6 @@ class TestPytestPluginInteractions(object): 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*"])