Session reference

Session

In nose2, all configuration for a test run is encapsulated in a Session instance. Plugins always have the session available as self.session.

class nose2.session.Session[source]

Configuration session.

Encapsulates all configuration for a given test run.

argparse

An instance of argparse.ArgumentParser. Plugins can use this directly to add arguments and argument groups, but must do so in their __init__ methods.

pluginargs

The argparse argument group in which plugins (by default) place their command-line arguments. Plugins can use this directly to add arguments, but must do so in their __init__ methods.

hooks

The nose2.events.PluginInterface instance contains all available plugin methods and hooks.

plugins

The list of loaded – but not necessarily active – plugins.

verbosity

Current verbosity level. Default: 1.

startDir

Start directory of test run. Test discovery starts here. Default: current working directory.

topLevelDir

Top-level directory of test run. This directory is added to sys.path. Default: starting directory.

libDirs

Names of code directories, relative to starting directory. Default: [‘lib’, ‘src’]. These directories are added to sys.path and discovery if the exist.

testFilePattern

Pattern used to discover test module files. Default: test*.py

testMethodPrefix

Prefix used to discover test methods and functions: Default: ‘test’.

unittest

The config section for nose2 itself.

configClass

alias of Config

get(section)[source]

Get a config section.

Parameters

section – The section name to retrieve.

Returns

instance of self.configClass.

isPluginLoaded(pluginName)[source]

Returns True if a given plugin is loaded.

Parameters

pluginName – the name of the plugin module: e.g. “nose2.plugins.layers”.

loadConfigFiles(*filenames)[source]

Load config files.

Parameters

filenames – Names of config files to load.

Loads all names files that exist into self.config.

loadPlugins(modules=None, exclude=None)[source]

Load plugins.

Parameters

modules – List of module names from which to load plugins.

loadPluginsFromModule(module)[source]

Load plugins from a module.

Parameters

module – A python module containing zero or more plugin classes.

prepareSysPath()[source]

Add code directories to sys.path

registerPlugin(plugin)[source]

Register a plugin.

Parameters

plugin – A nose2.events.Plugin instance.

Register the plugin with all methods it implements.

setStartDir(args_start_dir=None)[source]

start dir comes from config and may be overridden by an argument

setVerbosity(args_verbosity, args_verbose, args_quiet)[source]

Determine verbosity from various (possibly conflicting) sources of info

Parameters
  • args_verbosity – The –verbosity argument value

  • args_verbose – count of -v options

  • args_quiet – count of -q options

start with config, override with any given –verbosity, then adjust up/down with -vvv -qq, etc

Config

Configuration values loaded from config file sections are made available to plugins in Config instances. Plugins that set configSection will have a Config instance available as self.config.

class nose2.config.Config(items)[source]

Configuration for a plugin or other entities.

Encapsulates configuration for a single plugin or other element. Corresponds to a ConfigParser.Section but provides an extended interface for extracting items as a certain type.

as_bool(key, default=None)[source]

Get key value as boolean

1, t, true, on, yes and y (case insensitive) are accepted as True values. All other values are False.

as_float(key, default=None)[source]

Get key value as float

as_int(key, default=None)[source]

Get key value as integer

as_list(key, default=None)[source]

Get key value as list.

The value is split into lines and returned as a list. Lines are stripped of whitespace, and lines beginning with # are skipped.

as_str(key, default=None)[source]

Get key value as str

get(key, default=None)[source]

Get key value