diff --git a/changelog/155.removal.rst b/changelog/155.removal.rst new file mode 100644 index 00000000..baf0d130 --- /dev/null +++ b/changelog/155.removal.rst @@ -0,0 +1 @@ +Deprecate ``_Result.excinfo`` in favor of ``_Result.get_result()``. diff --git a/pluggy/callers.py b/pluggy/callers.py index 3ff67bec..4ffb4ed3 100644 --- a/pluggy/callers.py +++ b/pluggy/callers.py @@ -31,13 +31,28 @@ def __init__(self, result, excinfo): @property def excinfo(self): + """Get the exception info for this hook call (DEPRECATED in favor of + ``get_result()``). + """ + warnings.warn( + DeprecationWarning( + '`_Result.excinfo` is deprecated use `get_result()` to raise ' + 'the underlying exception'), + stacklevel=2 + ) return self._excinfo @property def result(self): - """Get the result(s) for this hook call (DEPRECATED in favor of ``get_result()``).""" - msg = 'Use get_result() which forces correct exception handling' - warnings.warn(DeprecationWarning(msg), stacklevel=2) + """Get the result(s) for this hook call (DEPRECATED in favor of + ``get_result()``). + """ + warnings.warn( + DeprecationWarning( + '`_Result.result` is deprecated use `get_result()` to force ' + 'correct exception handling'), + stacklevel=2 + ) return self._result @classmethod @@ -62,7 +77,7 @@ def force_result(self, result): self._excinfo = None def get_result(self): - """Get the result(s) for this hook call. + """Get the result(s) for this hook call; raises any caught exception. If the hook was marked as a ``firstresult`` only a single value will be returned otherwise a list of results. diff --git a/pluggy/manager.py b/pluggy/manager.py index bc0ea608..f39e06bb 100644 --- a/pluggy/manager.py +++ b/pluggy/manager.py @@ -297,7 +297,7 @@ def before(hook_name, methods, kwargs): hooktrace(hook_name, kwargs) def after(outcome, hook_name, methods, kwargs): - if outcome.excinfo is None: + if outcome._excinfo is None: hooktrace("finish", hook_name, "-->", outcome.get_result()) hooktrace.root.indent -= 1 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..9f2f621e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,6 @@ +[pytest] +filterwarnings = + once::DeprecationWarning + once::PendingDeprecationWarning + ignore:::pluggy + diff --git a/testing/test_deprecations.py b/testing/test_deprecations.py index 3000a374..27e19eb4 100644 --- a/testing/test_deprecations.py +++ b/testing/test_deprecations.py @@ -15,6 +15,17 @@ def test_result_deprecated(): assert r.result == 10 +def test_excinfo_deprecated(): + + def err(): + raise RuntimeError + + r = _Result.from_call(err) + + with pytest.deprecated_call(): + assert r.excinfo == r._excinfo + + def test_implprefix_deprecated(): with pytest.deprecated_call(): pm = PluginManager('blah', implprefix='blah_')