Skip to content

Commit 71c1cb3

Browse files
authored
Merge pull request #29 from pytest-dev/fix_historic_further
fix historic hook calling some more, add docstring
2 parents c883d1f + 04b0fda commit 71c1cb3

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
0.4.1
2+
-----
3+
4+
- fix bug where callbacks for historic hooks would not be called for
5+
already registered plugins. Thanks Simon Gmizelj for the PR
6+
and holger krekel for further fixes.
7+
18
0.4.0
29
-----
310

pluggy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import sys
6868
import inspect
6969

70-
__version__ = '0.4.0'
70+
__version__ = '0.4.1'
7171

7272
__all__ = ["PluginManager", "PluginValidationError", "HookCallError",
7373
"HookspecMarker", "HookimplMarker"]
@@ -745,11 +745,17 @@ def __call__(self, **kwargs):
745745
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
746746

747747
def call_historic(self, proc=None, kwargs=None):
748+
""" call the hook with given ``kwargs`` for all registered plugins and
749+
for all plugins which will be registered afterwards.
750+
751+
If ``proc`` is not None it will be called for for each non-None result
752+
obtained from a hook implementation.
753+
"""
748754
self._call_history.append((kwargs or {}, proc))
749755
# historizing hooks don't return results
750756
res = self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
751-
if res and proc is not None:
752-
proc(res[0])
757+
for x in res or []:
758+
proc(x)
753759

754760
def call_extra(self, methods, kwargs):
755761
""" Call the hook with some additional temporarily participating

testing/test_pluggy.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,37 @@ def he_method1(self, arg):
221221
pm.register(Plugin())
222222
assert l == [10]
223223

224-
def test_with_immediate_result_memorized(self, pm):
224+
def test_with_callbacks_immediately_executed(self, pm):
225225
class Hooks:
226226
@hookspec(historic=True)
227227
def he_method1(self, arg):
228228
pass
229229
pm.add_hookspecs(Hooks)
230230

231-
class Plugin:
231+
class Plugin1:
232232
@hookimpl
233233
def he_method1(self, arg):
234234
return arg * 10
235235

236+
class Plugin2:
237+
@hookimpl
238+
def he_method1(self, arg):
239+
return arg * 20
240+
241+
class Plugin3:
242+
@hookimpl
243+
def he_method1(self, arg):
244+
return arg * 30
245+
236246
l = []
237-
pm.register(Plugin())
247+
pm.register(Plugin1())
248+
pm.register(Plugin2())
238249

239250
he_method1 = pm.hook.he_method1
240251
he_method1.call_historic(lambda res: l.append(res), dict(arg=1))
241-
assert l == [10]
252+
assert l == [20, 10]
253+
pm.register(Plugin3())
254+
assert l == [20, 10, 30]
242255

243256
def test_register_historic_incompat_hookwrapper(self, pm):
244257
class Hooks:

0 commit comments

Comments
 (0)