Ensure a directory is on sys.path.

nose2.util.exc_info_to_string(err, test)[source]

Format exception info for output

nose2.util.format_traceback(test, err)[source]

Converts a sys.exc_info() -style tuple of values into a string.


Does this test live in a module with module fixtures?


Is this object a generator?


Is this path a package directory?

nose2.util.ln(label, char='-', width=70)[source]

Draw a divider, with label in the middle.

>>> ln('hello there')
'---------------------------- hello there -----------------------------'

width and divider char may be specified. Defaults are 70 and '-', respectively.


Import module from name

nose2.util.name_from_args(name, index, args)[source]

Create test name from test args


Translate path into module name

Returns a two-element tuple:

  1. a dotted module name that can be used in an import statement (e.g., pkg1.test.test_things)
  2. a full path to filesystem directory, which must be on sys.path for the import to succeed.
nose2.util.object_from_name(name, module=None)[source]

Given a dotted name, return the corresponding object.

Getting the object can fail for two reason:

  • the object is a module that cannot be imported.
  • the object is a class or a function that does not exists.

Since we cannot distinguish between these two cases, we assume we are in the first one. We expect the stacktrace is explicit enough for the user to understand the error.


Return numeric log level given a string


Safely decode a byte string into unicode

nose2.util.test_from_name(name, module)[source]

Import test from name

nose2.util.transplant_class(cls, module)[source]

Make cls appear to reside in module.

  • cls – A class
  • module – A module name

A subclass of cls that appears to have been defined in module.

The returned class’s __name__ will be equal to cls.__name__, and its __module__ equal to module.


Try to find the longest importable from the splitted_name, and return the corresponding module, as well as the potential ImportError exception that occurs when trying to import a longer name.

For instance, if splitted_name is [‘a’, ‘b’, ‘c’] but only a.b is importable, this function:

  1. tries to import a.b.c and fails
  2. tries to import a.b and succeeds
  3. return a.b and the exception that occured at step 1.

Is path a valid module name?