Profiling

Profile test execution using cProfile.

This plugin implements startTestRun() and replaces event.executeTests with cProfile.Profile.runcall(). It implements beforeSummaryReport() to output profiling information before the final test summary time. Config file options filename, sort and restrict can be used to change where profiling information is saved and how it is presented.

Load this plugin by running nose2 with the –plugin=nose2.plugins.prof option and activate it with the –profile option,or put the corresponding entries (plugin and always_on) in the respective sections of the configuration file.

Enable this Plugin

This plugin is built-in, but not loaded by default.

Even if you specify always-on = True in the configuration, it will not run unless you also enable it. You can do so by putting the following in a unittest.cfg or nose2.cfg file

[unittest]
plugins = nose2.plugins.prof

The plugins parameter may contain a list of plugin names, including nose2.plugins.prof

Configuration [profiler]

always-on
Default:

False

Type:

boolean

filename
Default:

Type:

str

restrict
Default:

[]

Type:

list

sort
Default:

cumulative

Type:

str

Sample configuration

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

[profiler]
always-on = False
filename = 
restrict = 
sort = cumulative

Command-line options

-P DEFAULT, --profile DEFAULT

Run tests under profiler

Plugin class reference: Profiler

class nose2.plugins.prof.Profiler(*args, **kwargs)[source]

Profile the test run

beforeSummaryReport(event)[source]

Output profiling results

startTestRun(event)[source]

Set up the profiler