From bee289c9b8685561f4aaee0b6f34be3863640a59 Mon Sep 17 00:00:00 2001 From: Ankit Goel Date: Tue, 16 Oct 2018 11:05:55 +0530 Subject: [PATCH] Adjust stacklevel of implprefix warning --- changelog/166.trivial.rst | 1 + pluggy/manager.py | 1 + testing/test_pluginmanager.py | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 changelog/166.trivial.rst diff --git a/changelog/166.trivial.rst b/changelog/166.trivial.rst new file mode 100644 index 00000000..5386c824 --- /dev/null +++ b/changelog/166.trivial.rst @@ -0,0 +1 @@ +Add ``stacklevel=2`` to implprefix warning so that the reported location of warning is the caller of PluginManager. diff --git a/pluggy/manager.py b/pluggy/manager.py index 3a90979e..dc3dfa9b 100644 --- a/pluggy/manager.py +++ b/pluggy/manager.py @@ -53,6 +53,7 @@ def __init__(self, project_name, implprefix=None): "Support for the `implprefix` arg is now deprecated and will " "be removed in an upcoming release. Please use HookimplMarker.", DeprecationWarning, + stacklevel=2, ) self._implprefix = implprefix self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall( diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 14a028a5..fc9cf32b 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -579,6 +579,12 @@ def he_method1(self): undo() +def test_implprefix_warning(recwarn): + PluginManager(hookspec.project_name, "hello_") + w = recwarn.pop(DeprecationWarning) + assert "test_pluginmanager.py" in w.filename + + @pytest.mark.parametrize("include_hookspec", [True, False]) def test_prefix_hookimpl(include_hookspec): with pytest.deprecated_call():