all Python 3until 3.13unittestfunction
unittest.findTestCases()
removed
Collected every test in a module into one suite. Removed in Python 3.13 — use TestLoader().loadTestsFromModule().
Syntax
unittest.findTestCases(module) # до 3.13
findTestCases(module) walked a module, picked up its TestCase classes and returned one TestSuite. It went away together with makeSuite and getTestCaseNames: all three merely repeated TestLoader methods. To migrate, replace unittest.findTestCases(mod) with unittest.TestLoader().loadTestsFromModule(mod). For the current file pass sys.modules[__name__]; for a whole directory loader.discover('tests') is handier.
Examples
# Python 3.13+
import unittest
try:
unittest.findTestCases
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.13+
import sys
import unittest
class MathTest(unittest.TestCase):
def test_add(self):
self.assertEqual(1 + 1, 2)
def test_mul(self):
self.assertEqual(2 * 3, 6)
module = sys.modules[__name__]
suite = unittest.TestLoader().loadTestsFromModule(module)
print(suite.countTestCases()) # → 2
import sys
import unittest
class MathTest(unittest.TestCase):
def test_add(self):
self.assertEqual(1 + 1, 2)
def test_mul(self):
self.assertEqual(2 * 3, 6)
suite = unittest.findTestCases(sys.modules[__name__])
print(suite.countTestCases()) # → 2
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy