Skip to content
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

Deprecate pytest namespace #3735

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
4 changes: 4 additions & 0 deletions changelog/2639.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``pytest_namespace`` has been deprecated.

See the documentation for ``pytest_namespace`` hook for suggestions on how to deal
with this in plugins which use this functionality.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main():
# if _PYTEST_SETUP_SKIP_PLUGGY_DEP is set, skip installing pluggy;
# used by tox.ini to test with pluggy master
if "_PYTEST_SETUP_SKIP_PLUGGY_DEP" not in os.environ:
install_requires.append("pluggy>=0.5,<0.8")
install_requires.append("pluggy>=0.7")
environment_marker_support_level = get_environment_marker_support_level()
if environment_marker_support_level >= 2:
install_requires.append('funcsigs;python_version<"3.0"')
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ class RemovedInPytest4Warning(DeprecationWarning):
"because it affects the entire directory tree in a non-explicit way.\n"
"Please move it to the top level conftest file instead."
)

PYTEST_NAMESPACE = RemovedInPytest4Warning(
"pytest_namespace is deprecated and will be removed soon"
)
18 changes: 16 additions & 2 deletions src/_pytest/hookspec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""" 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 @@ -22,17 +24,29 @@ def pytest_addhooks(pluginmanager):
"""


@hookspec(historic=True)
@hookspec(historic=True, warn_on_impl=PYTEST_NAMESPACE)
def pytest_namespace():
"""
(**Deprecated**) this hook causes direct monkeypatching on pytest, its use is strongly discouraged
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 its suggested to trigger ``DeprecationWarnings`` for objects they put into the
pytest namespace.

An 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.
"""


Expand Down
1 change: 1 addition & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_namespace_early_from_import(self, testdir):
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(
"""
Expand Down