File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -814,8 +814,13 @@ def class_wrapper(cls):
814
814
815
815
@inject (** bindings )
816
816
def init (self , * args , ** kwargs ):
817
- for key in original_keys :
818
- setattr (self , key , kwargs .pop (key .lstrip ('_' )))
817
+ try :
818
+ for key in original_keys :
819
+ normalized_key = key .lstrip ('_' )
820
+ setattr (self , key , kwargs .pop (normalized_key ))
821
+ except KeyError as e :
822
+ reraise (e , CallError ('Keyword argument %s not found' % normalized_key ))
823
+
819
824
orig_init (self , * args , ** kwargs )
820
825
cls .__init__ = init
821
826
return cls
Original file line number Diff line number Diff line change @@ -987,6 +987,17 @@ class X(object):
987
987
x = X (b = 314 )
988
988
assert (x ._b == 314 )
989
989
990
+ def test_correct_exception_is_raised_when_argument_is_missing (self ):
991
+ @inject (s = str )
992
+ class X (object ):
993
+ pass
994
+
995
+ with pytest .raises (CallError ):
996
+ self .B ()
997
+
998
+ with pytest .raises (CallError ):
999
+ self .B ('something' )
1000
+
990
1001
991
1002
def test_provides_and_scope_decorator_collaboration ():
992
1003
@provides (int )
You can’t perform that action at this time.
0 commit comments