# TestRunner¶

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

class htf.TestRunner(title='Test report', reports=None, metadata=None, workingDirectory=None, verbosity=1, failfast=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.

Parameters: 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.
run(test)

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

Parameters: test – a TestSuite or a TestCase.

Example:

from htf import TestCase

class SpecializedTestCase(TestCase):

def test_example():
self.assertTrue(True)

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

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.

# 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().

addSuccess(test)

Called when a test has completed successfully

addUnexpectedSuccess(test)

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

printErrors()

Called by TestRunner after test run

startTest(test)

Called when the given test is about to be run

startTestRun()

Called once before any tests are executed.

See startTest for a method called before each test.

stop()

Indicates that the tests should be aborted.

stopTest(test)

Called when the given test has been run

stopTestRun()

Called once after all tests are executed.

See stopTest for a method called after each test.

wasSuccessful()

Tells whether or not this result was a success.