Loader: Test Functions

Load tests from test functions in modules.

This plugin responds to loadTestsFromModule() by adding test cases for all test functions in the module to event.extraTests. It uses session.testMethodPrefix to find test functions.

Functions that are generators, have param lists, or take arguments are not collected.

This plugin also implements loadTestsFromName() to enable loading tests from dotted function names passed on the command line.


Test functions can specify setup and teardown fixtures as attributes on the function, for example:

x = 0

def test():
    assert x

def setup():
    global x
    x = 1

def teardown():
    global x
    x = 1

test.setup = setup
test.teardown = teardown

The setup attribute may be named setup, setUp or setUpFunc. The teardown attribute may be named teardown, tearDown or tearDownFunc.

Other attributes

The other significant attribute that may be set on a test function is paramList. When paramList is set, the function will be collected by the parameterized test loader. The easiest way to set paramList is with the nose2.tools.params() decorator.

Configuration [functions]


Sample configuration

The default configuration is equivalent to including the following in a unittest.cfg file.

always-on = True

Plugin class reference: Functions

class nose2.plugins.loader.functions.Functions[source]

Loader plugin that loads test functions


Load test functions from event.module


Load test if event.name is the name of a test function