File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -337,7 +337,11 @@ def set_specification(
337
337
specmodule_or_class : _Namespace ,
338
338
spec_opts : "_HookSpecOpts" ,
339
339
) -> None :
340
- assert not self .has_spec ()
340
+ if self .has_spec ():
341
+ raise RuntimeError (
342
+ f"Hook { self .spec .name !r} is already registered "
343
+ f"within namespace { self .spec .namespace } "
344
+ )
341
345
self .spec = HookSpec (specmodule_or_class , self .name , spec_opts )
342
346
if spec_opts .get ("historic" ):
343
347
self ._call_history = []
Original file line number Diff line number Diff line change @@ -405,3 +405,19 @@ def hello(self, arg: int) -> int:
405
405
pm .register (Plugin2 ())
406
406
with pytest .raises (PluginValidationError ):
407
407
pm .check_pending ()
408
+
409
+
410
+ def test_hook_conflict (pm : PluginManager ) -> None :
411
+ class Api1 :
412
+ @hookspec
413
+ def conflict (self ) -> None :
414
+ pass
415
+
416
+ class Api2 :
417
+ @hookspec
418
+ def conflict (self ) -> None :
419
+ pass
420
+
421
+ pm .add_hookspecs (Api1 )
422
+ with pytest .raises (RuntimeError ):
423
+ pm .add_hookspecs (Api2 )
You can’t perform that action at this time.
0 commit comments