-
Notifications
You must be signed in to change notification settings - Fork 66
ExtendingTestify
Testify has a plugin system that makes it easy to add in certain types of functionality without patching testify directly.
Testify comes with a few plugins that demonstrate the plugin system, as well as provide some useful functionality.
Adds a test result reporter to log test results to a file in JSON format.
Includes additional options --json-results
, --json-results-logging
and --extra-json-info
Uses the python coverage
package to generate coverage reports for your test cases
Uses cProfile
to generate a profiling data dump of each test method. These data files can then be used with normal cProfile
tools to analyze the performance of your code.
Testify by default includes in plugins within the testify/plugins/
directory.
Additional plugins can be included by providing them in the TESTIFY_PLUGIN_PATH
environment variable during test execution.
A plugin has access to a few different integration points. Testify will look at each module, and if a specially named function is provided, it will call it certain points during test execution.
Implement the add_command_line_options(parser)
function.
For example:
def add_command_line_options(parser):
parser.add_option("--do-awesome-stuff", dest="do_awesome_stuff", action="store_true", default=False)
After a test case class is instantiated, but before it is run, a plugin can gain access to the object and push whatever buttons it wants.
Plugins can do this by implementing the prepare_test_case(options, test_case)
function.
For example:
def prepare_test_case(options, test_case):
if options.do_awesome_stuff
test_case.awesome = True
A plugin can provide extra reporting hooks via the use of TestReporter objects. (see test_reporter.py
)
For example:
def build_test_reporters(options):
if options.log_awesome_stuff
return [AwesomeReporter()]
else:
return []
A plugin can wrap the execution of a test method by implementing the run_test_case(options, test_case, runnable)
function.
The plugin is expected to at some point during the execution of this function, run the argument runnable
.
For example:
def run_test_case(options, test_case, runnable):
try:
print "About to run test"
return runnable()
finally:
print "All done with test"