"""Loaders take a named test case and load the test appropriately."""from__future__importannotationsfromtypingimportTYPE_CHECKINGimportitertoolsfromattrsimportfield,frozenifTYPE_CHECKING:importtwisted.python.modulesfromvirtue.locatorsimportObjectLocator
[docs]@frozenclassAttributeLoader:""" I load a test case by instantiating a class with a given attribute name. This is the typical way that `unittest.TestCase` methods are loaded: by calling ``TestCase("test_something")`` (and then by calling :meth:`~unittest.TestCase.run` on the resulting instance to run the selected test method). """cls:typeattribute:str
[docs]defload(self):""" Load as a single test. """return[self.cls(self.attribute)]
[docs]@frozenclassModuleLoader:""" I load a test case by locating tests in the module with the given name. """locator:ObjectLocator=field(repr=False)module:twisted.python.modules.PythonModule
[docs]defload(self):""" Load all test cases in the module. """class_loaders=self.locator.locate_in_module(self.module.load())returnitertools.chain.from_iterable(class_loader.load()forclass_loaderinclass_loaders)