htf.TestRunner is used to start tests and to create test results.

Inheritance diagram of htf.TestRunner
class htf.TestRunner(title='Test report', reports=None, metadata=None, workingDirectory=None, verbosity=1, failfast=False, minimize_report_size=False)

A test runner class that displays renders in textual form, HTML form, XML form (like JUnit) and JSON form.

It prints out the names of tests as they are run, errors as they occur, and a summary of the results at the end of the test run.

Initialise a TestRunner object.

  • report" (title="Test) – a title for the test report.

  • reports – a list of test report instances or 2-tuples containing the file extension and the filename (HTMLTestReport, JunitXMLTestReport, JSONTestReport, etc.). If left empty an HTMLTestReport is generated.

  • metadata=None – metadata for the test run that can be shown in test report.

  • workingDirectory (str) – set working directory.

  • verbosity=1 (int) – verbosity.

  • failfast=False (bool) – if set to True, the test run stops after first failure or error.

  • minimize=False (bool) – if set to True, the captured data for successful and skipped tests is removed.


Run the given test case or test suite supplied by test.


test – a TestSuite or a TestCase.


from htf import TestCase

class SpecializedTestCase(TestCase):

    def test_example():

if __name__ == "__main__":
    from htf import TestLoader, TestRunner, HTMLTestReport

    suite = TestLoader().loadTestsFromTestCase(Test)

    result = TestRunner(title="A test", reports=[HTMLTestReport("test.html")], verbosity=2).run(suite)

The higher the verbosity level is the more verbose is the output to stderr and stdout.


Inheritance diagram of htf.TestResult
class htf.runner.TestResult(stream, descriptions, verbosity)

TestResult offers additional (temporal) information on top of unittest.TextTestResult.

Adds per run statistics to the output, e.g. success, failure rates and runtimes.

Expects the same arguments as unittest.TextTestResult.

addError(test, err)

Called when an error has occurred. ‘err’ is a tuple of values as returned by sys.exc_info().

addExpectedFailure(test, err)

Called when an expected failure/error occurred.

addFailure(test, err)

Called when an error has occurred. ‘err’ is a tuple of values as returned by sys.exc_info().

addSkip(test, reason)

Called when a test is skipped.

addSubTest(test, subtest, err)

Called at the end of a subtest. ‘err’ is None if the subtest ended successfully, otherwise it’s a tuple of values as returned by sys.exc_info().


Called when a test has completed successfully


Called when a test was expected to fail, but succeed.


Called by TestRunner after test run


Called when the given test is about to be run


Called once before any tests are executed.

See startTest for a method called before each test.


Indicates that the tests should be aborted.


Called when the given test has been run


Called once after all tests are executed.

See stopTest for a method called after each test.


Tells whether or not this result was a success.