File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,8 @@ def execute(self):
107
107
pass
108
108
109
109
if firstresult :
110
- return outcome .get_result ()[0 ]
110
+ result = outcome .get_result ()
111
+ return result [0 ] if result else None
111
112
112
113
return outcome .get_result ()
113
114
Original file line number Diff line number Diff line change @@ -92,3 +92,38 @@ def hello(self, arg):
92
92
pm .register (Plugin3 ()) # None result is ignored
93
93
res = pm .hook .hello (arg = 3 )
94
94
assert res == 2
95
+
96
+
97
+ def test_firstresult_returns_none (pm ):
98
+ """If None results are returned by underlying implementations ensure
99
+ the multi-call loop returns a None value.
100
+ """
101
+ class Api (object ):
102
+ @hookspec (firstresult = True )
103
+ def hello (self , arg ):
104
+ "api hook 1"
105
+
106
+ pm .add_hookspecs (Api )
107
+
108
+ class Plugin1 (object ):
109
+ @hookimpl
110
+ def hello (self , arg ):
111
+ return None
112
+
113
+ pm .register (Plugin1 ())
114
+ res = pm .hook .hello (arg = 3 )
115
+ assert res is None
116
+
117
+
118
+ def test_firstresult_no_plugin (pm ):
119
+ """If no implementations/plugins have been registered for a firstresult
120
+ hook the multi-call loop should return a None value.
121
+ """
122
+ class Api (object ):
123
+ @hookspec (firstresult = True )
124
+ def hello (self , arg ):
125
+ "api hook 1"
126
+
127
+ pm .add_hookspecs (Api )
128
+ res = pm .hook .hello (arg = 3 )
129
+ assert res is None
You can’t perform that action at this time.
0 commit comments