Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`trial`.`runner`.`TestLoader``

class documentation

`class TestLoader: (source)`

View In Hierarchy

I find tests inside function, modules, files -- whatever -- then return them wrapped inside a Test (either a `TestSuite` or a `TestCase`).

Method | `findByName` | Find and load tests, given `name`.
Method | `findTestClasses` | Given a module, return all Trial test classes
Method | `getTestCaseNames` | Given a class that contains `TestCase`s, return a list of names of methods that probably contain tests.
Method | `loadAnything` | Load absolutely anything (as long as that anything is a module, package, class, or method (with associated parent class and qualname).
Method | `loadByName` | Load some tests by name.
Method | `loadByNames` | Load some tests by a list of names.
Method | `loadClass` | Given a class which contains test cases, return a list of `TestCase`s.
Method | `loadDoctests` | Return a suite of tests for all the doctests defined in `module`.
Method | `loadFile` | Load a file, and then the tests in that file.
Method | `loadModule` | Return a test suite with all the tests from a module.
Method | `loadPackage` | Load tests from a module object representing a package, and return a TestSuite containing those tests.
Method | `sort` | Sort the given things using `sorter`.
Instance Variable | `forceGarbageCollection` | A flag applied to each `TestCase` loaded. See `unittest.TestCase` for more information.
Instance Variable | `methodPrefix` | A string prefix. `TestLoader` will assume that all the methods in a class that begin with `methodPrefix` are test cases.
Instance Variable | `modulePrefix` | A string prefix. Every module in a package that begins with `modulePrefix` is considered a module full of tests.
Instance Variable | `sorter` | A key function used to sort `TestCase`s, test classes, modules and packages.
Instance Variable | `suiteFactory` | A callable which is passed a list of tests (which themselves may be suites of tests). Must return a test suite.
Method | `_makeCase` | Undocumented
Method | `_uniqueTests` | Gather unique suite objects from loaded things. This will guarantee uniqueness of inherited methods on TestCases which would otherwise hash to same value and collapse to one test unexpectedly if using simpler means: e...

def findByName(self, _name, recurse=False): (source)

Find and load tests, given `name`.

Parameters
_name | The qualified name of the thing to load.
recurse | A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself.
Returns
If `name` is a filename, return the module. If `name` is a fully-qualified Python name, return the object it refers to.

def findTestClasses(self, module): (source)

Given a module, return all Trial test classes

def getTestCaseNames(self, klass): (source)

Given a class that contains `TestCase`s, return a list of names of methods that probably contain tests.

def loadAnything(self, obj, recurse=False, parent=None, qualName=None): (source)

Load absolutely anything (as long as that anything is a module, package, class, or method (with associated parent class and qualname).

Parameters
obj | The object to load.
recurse | A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself.
parent | If `obj` is a method, this is the parent class of the method. `qualName` is also required.
qualName | If `obj` is a method, this a list containing is the qualified name of the method. `parent` is also required.
Returns
A `TestCase` or `TestSuite`.

def loadByName(self, name, recurse=False): (source)

Load some tests by name.

Parameters
name | The qualified name for the test to load.
recurse | A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself.

def loadByNames(self, names: `List[str]`, recurse: `bool` = False) -> `TestSuite`: (source)

Load some tests by a list of names.

Parameters
names:`List[str]` | A `list` of qualified names.
recurse:`bool` | A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself.
Returns
`TestSuite` | Undocumented

def loadClass(self, klass): (source)

Given a class which contains test cases, return a list of `TestCase`s.

Parameters
klass | The class to load tests from.

def loadDoctests(self, module): (source)

Return a suite of tests for all the doctests defined in `module`.

Parameters
module | A module object or a module name.

def loadFile(self, fileName, recurse=False): (source)

Load a file, and then the tests in that file.

Parameters
fileName | The file name to load.
recurse | A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself.

def loadModule(self, module): (source)

Return a test suite with all the tests from a module.

Included are TestCase subclasses and doctests listed in the module's __doctests__ module. If that's not good for you, put a function named either `testSuite` or `test_suite` in your module that returns a TestSuite, and I'll use the results of that instead.

If `testSuite` and `test_suite` are both present, then I'll use `testSuite`.

def loadPackage(self, package, recurse=False): (source)

Load tests from a module object representing a package, and return a TestSuite containing those tests.

Tests are only loaded from modules whose name begins with 'test_' (or whatever `modulePrefix` is set to).

Parameters
package | a types.ModuleType object (or reasonable facsimile obtained by importing) which may contain tests.
recurse | A boolean. If True, inspect modules within packages within the given package (and so on), otherwise, only inspect modules in the package itself.
Returns
a TestSuite created with my suiteFactory, containing all the tests.
Raises
`TypeError` | If `package` is not a package.

def sort(self, xs): (source)

Sort the given things using `sorter`.

Parameters
xs | A list of test cases, class or modules.

forceGarbageCollection = (source)

A flag applied to each `TestCase` loaded. See `unittest.TestCase` for more information.

methodPrefix: `str` = (source)

A string prefix. `TestLoader` will assume that all the methods in a class that begin with `methodPrefix` are test cases.

modulePrefix: `str` = (source)

A string prefix. Every module in a package that begins with `modulePrefix` is considered a module full of tests.

sorter: `Callable[[_Loadable], object]` = (source)

A key function used to sort `TestCase`s, test classes, modules and packages.

suiteFactory: `Type[TestSuite]` = (source)

A callable which is passed a list of tests (which themselves may be suites of tests). Must return a test suite.

def _makeCase(self, klass, methodName): (source)

Undocumented

def _uniqueTests(self, things): (source)

Gather unique suite objects from loaded things. This will guarantee uniqueness of inherited methods on TestCases which would otherwise hash to same value and collapse to one test unexpectedly if using simpler means: e.g. set().