@@ -561,8 +561,14 @@ def __init__(self, method_name: str = "runTest", methodName: str = "runTest") ->
561
561
if methodName != "runTest" :
562
562
method_name = methodName
563
563
super ().__init__ (method_name )
564
- fn = getattr (self , method_name )
565
- setattr (self , method_name , self .join_or_run (fn ))
564
+ try :
565
+ fn = getattr (self , method_name )
566
+ setattr (self , method_name , self .join_or_run (fn ))
567
+ except AttributeError as e :
568
+ if methodName != 'runTest' :
569
+ # we allow instantiation with no explicit method name
570
+ # but not an *incorrect* or missing method name
571
+ raise ValueError (f"no such test method in { self .__class__ } : { methodName } " ) from e
566
572
567
573
def setUp (self ) -> None :
568
574
super ().setUp ()
@@ -1014,8 +1020,14 @@ def __init__(self, method_name: str = "runTest", methodName: str = "runTest") ->
1014
1020
if methodName != "runTest" :
1015
1021
method_name = methodName
1016
1022
super ().__init__ (method_name )
1017
- fn = getattr (self , method_name )
1018
- setattr (self , method_name , self .join_or_run (fn ))
1023
+ try :
1024
+ fn = getattr (self , method_name )
1025
+ setattr (self , method_name , self .join_or_run (fn ))
1026
+ except AttributeError as e :
1027
+ if methodName != 'runTest' :
1028
+ # we allow instantiation with no explicit method name
1029
+ # but not an *incorrect* or missing method name
1030
+ raise ValueError (f"no such test method in { self .__class__ } : { methodName } " ) from e
1019
1031
1020
1032
def perThreadSetUp (self ):
1021
1033
# super().setUp() # TestCase.setUp() calls torch.manual_seed()
0 commit comments