# Event reference

class nose2.events.CommandLineArgsEvent(args, **kw)

  Event fired after parsing of command line arguments.

  Plugins can respond to this event by configuring themselves or other plugins or modifying the parsed arguments.

  Note

  Many plugins register options with callbacks. By the time this event fires, those callbacks have already fired. So you can’t use this event to reliably influence all plugins.

  args

    Args object returned by argparse.

class nose2.events.CreateTestsEvent(loader, testNames, module, **kw)

  Event fired before test loading.

  Plugins can take over test loading by returning a test suite and setting `handled` on this event.

  loader

    Test loader instance

  names

    List of test names. May be empty or `None`.

  module

    Module to load from. May be `None`. If not `None`, names should be considered relative to this module.

class nose2.events.CreatedTestSuiteEvent(suite, **kw)

  Event fired after test loading.

  Plugins can replace the loaded test suite by returning a test suite and setting `handled` on this event.

  suite

    Test Suite instance

class nose2.events.DescribeTestEvent(test, description=None, errorList=False, **kw)

  Event fired to get test description.

  test

    The test case

  description

    Description of the test case. Plugins can set this to change how tests are described in output to users.

  errorList

    Is the event fired as part of error list output?

class nose2.events.Event(**metadata)

  Base class for all events.

  metadata

    Storage for arbitrary information attached to an event.

  handled

    Set to `True` to indicate that a plugin has handled the event, and no other plugins or core systems should process it further.

  version

    Version of the event API. This will be incremented with each release of nose2 that changes the API.

  version = '0.4'

class nose2.events.GetTestCaseNamesEvent(loader, testCase, isTestMethod, **kw)

  Event fired to find test case names in a test case.

  Plugins may return a list of names and set `handled` on this event to force test case name selection.

  loader

    Test loader instance

  testCase

    The `unittest.TestCase` instance being loaded.

  testMethodPrefix

    Set this to change the test method prefix. Unless set by a plugin, it is `None`.

  extraNames

    A list of extra test names to load from the test case. To cause extra tests to be loaded from the test case, append the names to this list. Note that the names here must be attributes of the test case.

  excludedNames

    A list of names to exclude from test loading. Add names to this list to prevent other plugins from loading the named tests.

  isTestMethod

    Callable that plugins can use to examine test case attributes to determine whether nose2 thinks they are test methods.

  excludedNames: list[str]
  extraNames: list[str]

class nose2.events.HandleFileEvent(loader, name, path, pattern, topLevelDirectory, **kw)

  Event fired when a non-test file is examined.

  Note

  This event is fired for all processed python files and modules including but not limited to the ones that match the test file pattern.

  loader

    Test loader instance

  name

    File basename

  path

    Full path to file

  pattern

    Current test file match pattern

  topLevelDirectory

    Top-level directory of the test run

  extraTests

    A list of extra tests loaded from the file. To load tests from a file without interfering with other plugins’ loading activities, append tests to extraTests.

  Plugins may set `handled` on this event and return a test suite to prevent other plugins from loading tests from the file. If any plugin sets `handled` to `True`, `extraTests` will be ignored.

  extraTests: list[TestCase]

class nose2.events.LoadFromModuleEvent(loader, module, **kw)

  Event fired when a test module is loaded.

  loader

    Test loader instance

  module

    The module whose tests are to be loaded

  extraTests

    A list of extra tests loaded from the module. To load tests from a module without interfering with other plugins’ loading activities, append tests to extraTests.

  Plugins may set `handled` on this event and return a test suite to prevent other plugins from loading tests from the module. If any plugin sets `handled` to `True`, `extraTests` will be ignored.

  extraTests: list[TestCase]

class nose2.events.LoadFromNameEvent(loader, name, module, **kw)

  Event fired to load tests from test names.

  loader

    Test loader instance

  name

    Test name to load

  module

    Module to load from. May be `None`. If not `None`, names should be considered relative to this module.

  extraTests

    A list of extra tests loaded from the name. To load tests from a test name without interfering with other plugins’ loading activities, append tests to extraTests.

  Plugins may set `handled` on this event and return a test suite to prevent other plugins from loading tests from the test name. If any plugin sets `handled` to `True`, `extraTests` will be ignored.

  extraTests: list[TestCase]

class nose2.events.LoadFromNamesEvent(loader, names, module, **kw)

  Event fired to load tests from test names.

  loader

    Test loader instance

  names

    List of test names. May be empty or `None`.

  module

    Module to load from. May be `None`. If not `None`, names should be considered relative to this module.

  extraTests

    A list of extra tests loaded from the tests named. To load tests from test names without interfering with other plugins’ loading activities, append tests to extraTests.

  Plugins may set `handled` on this event and return a test suite to prevent other plugins from loading tests from the test names. If any plugin sets `handled` to `True`, `extraTests` will be ignored.

  extraTests: list[TestCase]

class nose2.events.LoadFromTestCaseEvent(loader, testCase, **kw)

  Event fired when tests are loaded from a test case.

  loader

    Test loader instance

  testCase

    The `unittest.TestCase` instance being loaded.

  extraTests

    A list of extra tests loaded from the module. To load tests from a test case without interfering with other plugins’ loading activities, append tests to extraTests.

  Plugins may set `handled` on this event and return a test suite to prevent other plugins from loading tests from the test case. If any plugin sets `handled` to `True`, `extraTests` will be ignored.

  extraTests: list[TestCase]

class nose2.events.MatchPathEvent(name, path, pattern, **kw)

  Event fired during file matching.

  Plugins may return `False` and set `handled` on this event to prevent a file from being matched as a test file, regardless of other system settings.

  path

    Full path to the file

  name

    File basename

  pattern

    Current test file match pattern

class nose2.events.ModuleSuiteEvent(loader, module, suite, **kw)

class nose2.events.OutcomeDetailEvent(outcomeEvent, **kw)

  Event fired to acquire additional details about test outcome.

  outcomeEvent

    A `nose2.events.TestOutcomeEvent` instance holding the test outcome to be described.

  extraDetail

    Extra detail lines to be appended to test outcome output. Plugins can append lines (of strings) to this list to include their extra information in the error list report.

  extraDetail: list[str]

class nose2.events.PluginsLoadedEvent(pluginsLoaded, **kw)

  Event fired after all plugin classes are loaded.

  pluginsLoaded

    List of all loaded plugin classes

class nose2.events.ReportSummaryEvent(stopTestEvent, stream, reportCategories, **kw)

  Event fired before and after summary report.

  stopTestEvent

    A `nose2.events.StopTestEvent` instance.

  stream

    The output stream. Plugins can set this to change or capture output.

  reportCategories

    Dictionary of report category and test events captured in that category. Default categories include ‘errors’, ‘failures’, ‘skipped’, ‘expectedFails’, and ‘unexpectedSuccesses’. Plugins may add their own categories.

class nose2.events.ReportTestEvent(testEvent, stream, **kw)

  Event fired to report a test event.

  Plugins can respond to this event by producing output for the user.

  testEvent

    A test event. In most cases, a `nose2.events.TestOutcomeEvent` instance. For startTest, a `nose2.events.StartTestEvent` instance.

  stream

    The output stream. Plugins can set this to change or capture output.

class nose2.events.ResultCreatedEvent(result, **kw)

  Event fired when test result handler is created.

  result

    Test result handler instance. Plugins may replace the test result by setting this attribute to a new test result instance.

class nose2.events.ResultStopEvent(result, shouldStop, **kw)

  Event fired when a test run is told to stop.

  Plugins can use this event to prevent other plugins from stopping a test run.

  result

    Test result

  shouldStop

    Set to `True` to indicate that the test run should stop.

class nose2.events.ResultSuccessEvent(result, success, **kw)

  Event fired at end of test run to determine success.

  This event fires at the end of the test run and allows plugins to determine whether the test run was successful.

  result

    Test result

  success

    Set this to `True` to indicate that the test run was successful. If no plugin sets the `success` to `True`, the test run fails. Should be initialized to `None` to indicate that the status has not been set yet (so that plugins can always differentiate an explicit failure in an earlier hook from no pass/fail status having been set yet.

class nose2.events.RunnerCreatedEvent(runner, **kw)

  Event fired when test runner is created.

  runner

    Test runner instance. Plugins may replace the test runner by setting this attribute to a new test runner instance.

class nose2.events.StartLayerSetupEvent(layer, **kw)

  Event fired before running a layer setup.

  layer

    The current layer instance, for which setup is about to run.

class nose2.events.StartLayerSetupTestEvent(layer, test, **kw)

  Event fired before test cases setups in layers.

  layer

    The current layer instance.

  test

    The test instance for which the setup is about to run.

class nose2.events.StartLayerTeardownEvent(layer, **kw)

  Event fired before running a layer teardown.

  layer

    The current layer instance, for which teardown is about to run.

class nose2.events.StartLayerTeardownTestEvent(layer, test, **kw)

  Event fired before test cases teardowns in layers.

  layer

    The current layer instance.

  test

    The test instance for which teardown is about to run.

class nose2.events.StartTestEvent(test, result, startTime, **kw)

  Event fired before a test is executed.

  test

    The test case

  result

    Test result

  startTime

    Timestamp of test start

class nose2.events.StartTestRunEvent(runner, suite, result, startTime, executeTests, **kw)

  Event fired when test run is about to start.

  Test collection is complete before this event fires, but no tests have yet been executed.

  runner

    Test runner

  suite

    Top-level test suite to execute. Plugins can filter this suite, or set event.suite to change which tests execute (or how they execute).

  result

    Test result

  startTime

    Timestamp of test run start

  executeTests

    Callable that will be used to execute tests. Plugins may set this attribute to wrap or otherwise change test execution. The callable must match the signature:

        def execute(suite, result):
            ...

  To prevent normal test execution, plugins may set `handled` on this event to `True`. When `handled` is true, the test executor does not run at all.

class nose2.events.StopLayerSetupEvent(layer, **kw)

  Event fired after running a layer setup.

  layer

    The current layer instance, for which setup just ran.

class nose2.events.StopLayerSetupTestEvent(layer, test, **kw)

  Event fired after test cases setups in layers.

  layer

    The current layer instance.

  test

    The test instance for which the setup just finished.

class nose2.events.StopLayerTeardownEvent(layer, **kw)

  Event fired after running a layer teardown.

  layer

    The current layer instance, for which teardown just ran.

class nose2.events.StopLayerTeardownTestEvent(layer, test, **kw)

  Event fired after test cases teardowns in layers.

  layer

    The current layer instance.

  test

    The test instance for which teardown just ran.

class nose2.events.StopTestEvent(test, result, stopTime, **kw)

  Event fired after a test is executed.

  test

    The test case

  result

    Test result

  stopTime

    Timestamp of test stop

class nose2.events.StopTestRunEvent(runner, result, stopTime, timeTaken, **kw)

  Event fired when test run has stopped.

  runner

    Test runner

  result

    Test result

  stopTime

    Timestamp of test run stop

  timeTaken

    Number of seconds test run took to execute

class nose2.events.TestOutcomeEvent(test, result, outcome, exc_info=None, reason=None, expected=False, shortLabel=None, longLabel=None, **kw)

  Event fired when a test completes.

  test

    The test case

  result

    Test result

  outcome

    Description of test outcome. Typically will be one of ‘error’, ‘failed’, ‘skipped’, ‘passed’, or ‘subtest’.

  exc_info

    If the test resulted in an exception, the tuple of (exception class, exception value, traceback) as returned by `sys.exc_info()`. If the test did not result in an exception, `None`.

  reason

    For test outcomes that include a reason (`Skips`, for example), the reason.

  expected

    Boolean indicating whether the test outcome was expected. In general, all tests are expected to pass, and any other outcome will have expected as `False`. The exceptions to that rule are unexpected successes and expected failures.

  shortLabel

    A short label describing the test outcome. (For example, ‘E’ for errors).

  longLabel

    A long label describing the test outcome (for example, ‘ERROR’ for errors).

  Plugins may influence how the rest of the system sees the test outcome by setting `outcome` or `exc_info` or `expected`. They may influence how the test outcome is reported to the user by setting `shortLabel` or `longLabel`.

class nose2.events.UserInteractionEvent(**kw)

  Event fired before and after user interaction.

  Plugins that capture stdout or otherwise prevent user interaction should respond to this event.

  To prevent the user interaction from occurring, return `False` and set `handled`. Otherwise, turn off whatever you are doing that prevents users from typing/clicking/touching/psionics/whatever.