Functest has a full featured reporting framework so that you can define how to report results in your tests

When is this useful?

When your continuous integration system wants a particular output from a test run.

When you're running a distributed project where multiple developers and testers are running tests and you would like people to register the results of their tests before they checkin changes.

How do I use it

The best place to put your Report definition is in the root module for your tests. This module will always get imported when functest compiles the dependency chain.

from functest import reports
import sys

class MyReport(reports.FunctestReportInterface):
    def summary(self, test_list, totals_dict, stdout_capture):
        sys.__stdout__.write("all tests list "+str(test_list)+'\n')
        sys.__stdout__.write('--stdout--'+stdout_capture)
        sys.__stdout__.flush()

reports.register_reporter(MyReport())
  1. The summary method is called after all the tests have run, it has a list of every test function passed to it and a string of all the captured stdout (if you're Runner has implemented the proper method like the default functest Runner).
  2. test_list is the first argument passed to final, it is a list of every test function that was run. Keep in mind that setup and teardown functions are also in this. Each function has a "result" attribute which is a bool for the test result.
  3. totals_dict is the seconds argument. It's a dictionary of "pass", "fail", and "skipped" with integers for each value.
  4. stdout_capture is the third argument. It's a string of all the stdout that was captured, any print statements or tracebacks will be here. If your test runner doesn't define a method for getting back this capture or doesn't support capturing stdout then an empty string will be passed.
  5. reports.register_reporter get an instance of your report class and registers it in functest. Since we're doing this in the base module scope it will get registered when this module is imported. You can register as many report classes as you want and they will all be used.

Although that example gave you a good idea of what you can do it doesn't show you how granular you can get reports, or the kind of information functest attaches to each function.

Real Time Reporter

class MyRealTimeReport(reports.FunctestReportInterface):
    def test_function(self, test_function):
        sys.__stdout__.write("Finished test_function: "+test_function.__name__)
    def setup_module(self, test_function):
        sys.__stdout__.write("Finished setup_module: "+test_function.module.__name__)
    def teardown_module(self, test_function):
        sys.__stdout__.write("Finished teardown_module: "+test_function.module.__name__)

This reporter's functions will get called as the each test passes. The functions are seperated by test_type which is either setup_module, teardown_module, or test_function.