Skip to content

Commit

Permalink
Deprecate proc kwarg to call_historic()
Browse files Browse the repository at this point in the history
It's a bad name, use `result_callback` instead.

Resolves pytest-dev#120
  • Loading branch information
Tyler Goodlet committed May 18, 2018
1 parent 119836b commit 0333b83
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
26 changes: 19 additions & 7 deletions pluggy/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,32 @@ def __call__(self, *args, **kwargs):
)
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)

def call_historic(self, proc=None, kwargs=None):
""" call the hook with given ``kwargs`` for all registered plugins and
def call_historic(self, result_callback=None, kwargs=None, proc=None):
"""Call the hook with given ``kwargs`` for all registered plugins and
for all plugins which will be registered afterwards.
If ``proc`` is not None it will be called for for each non-None result
obtained from a hook implementation.
If ``result_callback`` is not ``None`` it will be called for for each
non-None result obtained from a hook implementation.
.. note::
The ``proc`` argument is now deprecated.
"""
self._call_history.append((kwargs or {}, proc))
if proc is not None:
warnings.warn(
"Support for `proc` argument is now deprecated and will be"
"removed in an upcoming release.",
DeprecationWarning
)
result_callback = proc

self._call_history.append((kwargs or {}, result_callback))
# historizing hooks don't return results
res = self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
if proc is None:
if result_callback is None:
return
# XXX: remember firstresult isn't compat with historic
for x in res or []:
proc(x)
result_callback(x)

def call_extra(self, methods, kwargs):
""" Call the hook with some additional temporarily participating
Expand Down
19 changes: 18 additions & 1 deletion testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def he_method1(self, arg):
pm.register(Plugin1())

he_method1 = pm.hook.he_method1
he_method1.call_historic(proc=callback, kwargs=dict(arg=1))
he_method1.call_historic(result_callback=callback, kwargs=dict(arg=1))

class Plugin2(object):
@hookimpl
Expand Down Expand Up @@ -399,3 +399,20 @@ def example_hook():
assert getattr(pm.hook, 'example_hook', None) # conftest.example_hook should be collected
assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None
assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}


def test_callhistoric_proc_deprecated(pm):
"""``proc`` kwarg to `PluginMananger.call_historic()` is now officially
deprecated.
"""
class P1(object):
@hookspec(historic=True)
@hookimpl
def m(self, x):
pass

p1 = P1()
pm.add_hookspecs(p1)
pm.register(p1)
with pytest.deprecated_call():
pm.hook.m.call_historic(kwargs=dict(x=10), proc=lambda res: res)

0 comments on commit 0333b83

Please sign in to comment.