File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -357,7 +357,11 @@ def set_specification(
357
357
specmodule_or_class : _Namespace ,
358
358
spec_opts : _HookSpecOpts ,
359
359
) -> None :
360
- assert not self .has_spec ()
360
+ if self .spec is not None :
361
+ raise ValueError (
362
+ f"Hook { self .spec .name !r} is already registered "
363
+ f"within namespace { self .spec .namespace } "
364
+ )
361
365
self .spec = HookSpec (specmodule_or_class , self .name , spec_opts )
362
366
if spec_opts .get ("historic" ):
363
367
self ._call_history = []
Original file line number Diff line number Diff line change @@ -428,3 +428,23 @@ def hello(self, arg: int) -> int:
428
428
pm .register (Plugin2 ())
429
429
with pytest .raises (PluginValidationError ):
430
430
pm .check_pending ()
431
+
432
+
433
+ def test_hook_conflict (pm : PluginManager ) -> None :
434
+ class Api1 :
435
+ @hookspec
436
+ def conflict (self ) -> None :
437
+ """Api1 hook"""
438
+
439
+ class Api2 :
440
+ @hookspec
441
+ def conflict (self ) -> None :
442
+ """Api2 hook"""
443
+
444
+ pm .add_hookspecs (Api1 )
445
+ with pytest .raises (ValueError ) as exc :
446
+ pm .add_hookspecs (Api2 )
447
+ assert str (exc .value ) == (
448
+ "Hook 'conflict' is already registered within namespace "
449
+ "<class 'test_hookcaller.test_hook_conflict.<locals>.Api1'>"
450
+ )
You can’t perform that action at this time.
0 commit comments