import unittest def testSomething(): something = makeSomething() assert something.name is not None # . . . # Below is what the documentation suggests, but this is ignored by the # automatic test discovery, and cannot be manually run either testcase = unittest.FunctionTestCase(testSomething) # Okay, so TestLoader.loadTestsFromName() does not support naming actual test # instances. But assuming FunctionTestCase subclasses TestCase, the following # subclass should be both discoverable and manually runnable. However it is a # lot more work than suggested by the documentation. class FunctionSubclass(unittest.FunctionTestCase): def __init__(self, methodName=None): # See Issue 22153 unittest.FunctionTestCase.__init__(self, testSomething) # In fact, it seems simpler to avoid FunctionTestCase: class Simpler(unittest.TestCase): def runTest(self): testSomething()