Skip to content
guilhermechapiewski edited this page Sep 13, 2010 · 6 revisions

You can implement hooks to execute your own tasks using Pyccuracy data. Hooks are executed in determined points during Pyccuracy execution. Hook classes must be located anywhere inside Pyccuracy tests directory. You can also use “-H” option in “pyccuracy_console” if you want to setup a different hooks directory.

1) Before Tests Hook

“Before Tests Hooks” are executed before the tests execution. This type of hook allows you to do things like populating your database, setting up environment and anything you need to do before tests are executed.

To create this type of hook, you will need to implement a class that inherits from BeforeTestsHook and implement the execute method:

from pyccuracy.hooks import BeforeTestsHook

class PopulateDB(BeforeTestsHook):
    def execute(self):
        # do my stuff

2) After Tests Hook

“After Tests Hooks” are executed after all Pyccuracy tests finish their execution. This type of hook gives you the test execution data, allowing you to do many sorts of things like writing your test results to a wiki page, or even creating your own customized test reports.

To create this type of hook, you will need to implement a class that inherits from AfterTestsHook and implement the execute method:

from pyccuracy.hooks import AfterTestsHook

class GenerateMyReports(AfterTestsHook):
    def execute(self, results):
        # generate my reports using 'results' object

After Pyccuracy executes your tests, it will invoke the execute method of your hook passing the results parameter – an object of type pyccuracy.result.Result which contains the test execution data.

3) Other hooks

Currently no other hooks are supported. Please see “Requesting features, reporting bugs and contributing” if you want to contribute with new hooks (or even ideas/special needs you might have).