File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -1589,7 +1589,7 @@ def stop(self):
1589
1589
def _get_target (target ):
1590
1590
try :
1591
1591
target , attribute = target .rsplit ('.' , 1 )
1592
- except (TypeError , ValueError ):
1592
+ except (TypeError , ValueError , AttributeError ):
1593
1593
raise TypeError ("Need a valid target to patch. You supplied: %r" %
1594
1594
(target ,))
1595
1595
return partial (pkgutil .resolve_name , target ), attribute
Original file line number Diff line number Diff line change @@ -1933,8 +1933,13 @@ def test(mock):
1933
1933
1934
1934
1935
1935
def test_invalid_target (self ):
1936
- with self .assertRaises (TypeError ):
1937
- patch ('' )
1936
+ class Foo :
1937
+ pass
1938
+
1939
+ for target in ['' , 12 , Foo ()]:
1940
+ with self .subTest (target = target ):
1941
+ with self .assertRaises (TypeError ):
1942
+ patch (target )
1938
1943
1939
1944
1940
1945
def test_cant_set_kwargs_when_passing_a_mock (self ):
You can’t perform that action at this time.
0 commit comments