@@ -84,9 +84,13 @@ def loadTestsFromTestCase(self, testCaseClass):
8484 raise TypeError ("Test cases should not be derived from "
8585 "TestSuite. Maybe you meant to derive from "
8686 "TestCase?" )
87- testCaseNames = self .getTestCaseNames (testCaseClass )
88- if not testCaseNames and hasattr (testCaseClass , 'runTest' ):
89- testCaseNames = ['runTest' ]
87+ if testCaseClass in (case .TestCase , case .FunctionTestCase ):
88+ # We don't load any tests from base types that should not be loaded.
89+ testCaseNames = []
90+ else :
91+ testCaseNames = self .getTestCaseNames (testCaseClass )
92+ if not testCaseNames and hasattr (testCaseClass , 'runTest' ):
93+ testCaseNames = ['runTest' ]
9094 loaded_suite = self .suiteClass (map (testCaseClass , testCaseNames ))
9195 return loaded_suite
9296
@@ -95,7 +99,11 @@ def loadTestsFromModule(self, module, *, pattern=None):
9599 tests = []
96100 for name in dir (module ):
97101 obj = getattr (module , name )
98- if isinstance (obj , type ) and issubclass (obj , case .TestCase ):
102+ if (
103+ isinstance (obj , type )
104+ and issubclass (obj , case .TestCase )
105+ and obj not in (case .TestCase , case .FunctionTestCase )
106+ ):
99107 tests .append (self .loadTestsFromTestCase (obj ))
100108
101109 load_tests = getattr (module , 'load_tests' , None )
@@ -164,7 +172,11 @@ def loadTestsFromName(self, name, module=None):
164172
165173 if isinstance (obj , types .ModuleType ):
166174 return self .loadTestsFromModule (obj )
167- elif isinstance (obj , type ) and issubclass (obj , case .TestCase ):
175+ elif (
176+ isinstance (obj , type )
177+ and issubclass (obj , case .TestCase )
178+ and obj not in (case .TestCase , case .FunctionTestCase )
179+ ):
168180 return self .loadTestsFromTestCase (obj )
169181 elif (isinstance (obj , types .FunctionType ) and
170182 isinstance (parent , type ) and
0 commit comments