remove pytest namespace hook
This commit is contained in:
parent
62967b3110
commit
ba17363d75
|
@ -0,0 +1 @@
|
||||||
|
Remove the implementation of the pytest_namespace hook.
|
|
@ -610,13 +610,6 @@ class Config(object):
|
||||||
self.pluginmanager.register(self, "pytestconfig")
|
self.pluginmanager.register(self, "pytestconfig")
|
||||||
self._configured = False
|
self._configured = False
|
||||||
self.invocation_dir = py.path.local()
|
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))
|
self.hook.pytest_addoption.call_historic(kwargs=dict(parser=self._parser))
|
||||||
|
|
||||||
def add_cleanup(self, func):
|
def add_cleanup(self, func):
|
||||||
|
|
|
@ -113,9 +113,6 @@ PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning(
|
||||||
"Please move it to the top level conftest file instead."
|
"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_ENSURETEMP = RemovedInPytest4Warning(
|
||||||
"pytest/tmpdir_factory.ensuretemp is deprecated, \n"
|
"pytest/tmpdir_factory.ensuretemp is deprecated, \n"
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """
|
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """
|
||||||
from pluggy import HookspecMarker
|
from pluggy import HookspecMarker
|
||||||
|
|
||||||
from .deprecated import PYTEST_NAMESPACE
|
|
||||||
|
|
||||||
|
|
||||||
hookspec = HookspecMarker("pytest")
|
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)
|
@hookspec(historic=True)
|
||||||
def pytest_plugin_registered(plugin, manager):
|
def pytest_plugin_registered(plugin, manager):
|
||||||
""" a new pytest plugin got registered.
|
""" a new pytest plugin got registered.
|
||||||
|
|
|
@ -59,37 +59,6 @@ class TestPytestPluginInteractions(object):
|
||||||
assert res.ret != 0
|
assert res.ret != 0
|
||||||
res.stderr.fnmatch_lines(["*did not find*sys*"])
|
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):
|
def test_do_option_postinitialize(self, testdir):
|
||||||
config = testdir.parseconfigure()
|
config = testdir.parseconfigure()
|
||||||
assert not hasattr(config.option, "test123")
|
assert not hasattr(config.option, "test123")
|
||||||
|
@ -190,17 +159,6 @@ class TestPytestPluginInteractions(object):
|
||||||
assert "deprecated" in warnings[-1]
|
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):
|
def test_default_markers(testdir):
|
||||||
result = testdir.runpytest("--markers")
|
result = testdir.runpytest("--markers")
|
||||||
result.stdout.fnmatch_lines(["*tryfirst*first*", "*trylast*last*"])
|
result.stdout.fnmatch_lines(["*tryfirst*first*", "*trylast*last*"])
|
||||||
|
|
Loading…
Reference in New Issue