nose: nose.loader

nose's test loader implements the same basic functionality as its superclass, unittest.TestLoader, but extends it by more liberal interpretations of what may be a test and how a test may be named.

Classes

Highlighted methods are defined in this class.

TestLoader (unittest.TestLoader)

Test loader that extends unittest.TestLoader to:

  • Load tests from test-like functions and classes that are not unittest.TestCase subclasses
  • Find and load test modules in a directory
  • Support tests that are generators
  • Support easy extensions of or changes to that behavior through plugins

Methods

__init__(self, config=None, importer=None, workingDir=None, selector=None)

Initialize a test loader.

Parameters (all optional):

  • config: provide a nose.config.Config or other config class instance; if not provided a nose.config.Config with default values is used.
  • importer: provide an importer instance that implements importFromPath. If not provided, a nose.importer.Importer is used.
  • workingDir: the directory to which file and module names are relative. If not provided, assumed to be the current working directory.
  • selector: a selector class or instance. If a class is provided, it will be instantiated with one argument, the current config. If not provided, a nose.selector.Selector is used.
getTestCaseNames(self, testCaseClass)

Override to select with selector, unless config.getTestCaseNamesCompat is True

loadTestsFromDir(self, path)

Load tests from the directory at path. This is a generator -- each suite of tests from a module or other file is yielded and is expected to be executed before the next file is examined.

loadTestsFromFile(self, filename)

Load tests from a non-module file. Default is to raise a ValueError; plugins may implement loadTestsFromFile to provide a list of tests loaded from the file.

loadTestsFromGenerator(self, generator, module)

Lazy-load tests from a generator function. The generator function may yield either:

  • a callable, or
  • a function name resolvable within the same module
loadTestsFromGeneratorMethod(self, generator, cls)

Lazy-load tests from a generator method.

This is more complicated than loading from a generator function, since a generator method may yield:

  • a function
  • a bound or unbound method, or
  • a method name
loadTestsFromModule(self, module, discovered=False)

Load all tests from module and return a suite containing them. If the module has been discovered and is not test-like, the suite will be empty by default, though plugins may add their own tests.

loadTestsFromName(self, name, module=None, discovered=False)

Load tests from the entity with the given name.

The name may indicate a file, directory, module, or any object within a module. See nose.util.split_test_name for details on test name parsing.

loadTestsFromNames(self, names, module=None)

Load tests from all names, returning a suite containing all tests.

loadTestsFromTestCase(self, testCaseClass)

Load tests from a unittest.TestCase subclass.

loadTestsFromTestClass(self, cls)

Load tests from a test class that is not a unittest.TestCase subclass.

In this case, we can't depend on the class's __init__ taking method name arguments, so we have to compose a MethodTestCase for each method in the class that looks testlike.

makeTest(self, obj, parent=None)

Given a test object and its parent, return a test case or test suite.

resolve(self, name, module)

Resolve name within module

sortTestMethodsUsing(...)(inherited from TestLoader)

cmp(x, y) -> integer

Return negative if x<y, zero if x==y, positive if x>y.

Attributes

config
Default value: None
importer
Default value: None
selector
Default value: None
suiteClass
Default value: None
testMethodPrefix
Default value: test
workingDir
Default value: None
defaultTestLoader (unittest.TestLoader)
(Alias for TestLoader)