@@ -84,9 +84,13 @@ def loadTestsFromTestCase(self, testCaseClass):
84
84
raise TypeError ("Test cases should not be derived from "
85
85
"TestSuite. Maybe you meant to derive from "
86
86
"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' ]
90
94
loaded_suite = self .suiteClass (map (testCaseClass , testCaseNames ))
91
95
return loaded_suite
92
96
@@ -95,7 +99,11 @@ def loadTestsFromModule(self, module, *, pattern=None):
95
99
tests = []
96
100
for name in dir (module ):
97
101
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
+ ):
99
107
tests .append (self .loadTestsFromTestCase (obj ))
100
108
101
109
load_tests = getattr (module , 'load_tests' , None )
@@ -164,7 +172,11 @@ def loadTestsFromName(self, name, module=None):
164
172
165
173
if isinstance (obj , types .ModuleType ):
166
174
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
+ ):
168
180
return self .loadTestsFromTestCase (obj )
169
181
elif (isinstance (obj , types .FunctionType ) and
170
182
isinstance (parent , type ) and
0 commit comments