unittest loaders should avoid loading test cases that are abstract base classes #120665
Copy link
Copy link
Closed
Closed
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jun 18, 2024 See also previous discussion in #58739.
Until this issue is resolved, I hope this little snippet helps someone:
import inspect import unittest # ... class MyTestLoader(unittest.TestLoader): def loadTestsFromTestCase(self, testCaseClass): if inspect.isabstract(testCaseClass): return self.suiteClass() return super().loadTestsFromTestCase(testCaseClass) if __name__ == "__main__": unittest.main(verbosity=2, testLoader=MyTestLoader())
- added a commit that references this issue
on Jun 17, 2026 - marked Add means to mark unittest.TestCases as "do not load". #58739 as a duplicate of this issue
on Jun 17, 2026
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Bug report
Bug description:
As reported in Discourse, loading a
TestCase-derived subclass that is also an abstract base class like the following:would currently result in:
We should make the unittest loaders avoid loading such test cases and methods from them.
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
Linux, Windows
Linked PRs