html_reporter.runner

This module contains the HTMLTestRunner class.

Module Contents

Classes

TestCaseReport

Class to keep track of a test case report which is used by the Jinja2

TestGroupReport

Class to keep track of a test group report which is used by the

HTMLTestRunner

The main HTMLTestRunner class.

Attributes

DEFAULT_TEMPLATE

html_reporter.runner.DEFAULT_TEMPLATE[source]
class html_reporter.runner.TestCaseReport[source]

Class to keep track of a test case report which is used by the Jinja2 template.

Parameters
  • tid (str) – HTML test case ID (e.g., ‘pt1.1’, ‘ft1.1’, ‘et1.1’, ‘st1.1’)

  • desc (str) – test case description

  • status (TestStatus) – test case status

  • detail (str) – test case detail

tid :str[source]
desc :str[source]
status :html_reporter.status.TestStatus[source]
detail :str[source]
class html_reporter.runner.TestGroupReport[source]

Class to keep track of a test group report which is used by the Jinja2 template.

Parameters
  • cid (str) – HTML test group ID (e.g., ‘c1’)

  • desc (str) – test group description

  • pass_count (int) – number of passed test cases

  • fail_count (int) – number of failed test cases

  • error_count (int) – number of error test cases

  • skip_count (int) – number of skipped test cases

  • test_cases (List[TestCaseReport]) – list of test case reports

cid :str[source]
desc :str[source]
pass_count :int[source]
fail_count :int[source]
error_count :int[source]
skip_count :int[source]
test_cases :List[TestCaseReport][source]
total_count()[source]
class html_reporter.runner.HTMLTestRunner(report_filepath: Union[str, pathlib.Path], verbosity: int = 1, title: str = 'Unit Test Report', description: str = 'Unit Test Report Description', template: Union[str, pathlib.Path] = None, open_in_browser: bool = False)[source]

Bases: object

The main HTMLTestRunner class.

Constructor.

Parameters
  • report_filepath (Union[str, Path]) – path to the report output file

  • verbosity (int, optional) – verbosity, defaults to 1

  • title (str, optional) – HTML page title, defaults to “Unit Test Report”

  • description (str, optional) – description of the report, defaults to “Unit Test Report Description”

  • template (Union[str, Path], optional) – path to the template file, if nothing is given, it uses the default template, defaults to None

  • open_in_browser (bool, optional) – option to open the report file in browser after rendering, defaults to False

run(test: Union[unittest.TestCase, unittest.TestSuite]) html_reporter.result.HTMLTestResult[source]

Run the given test case or test suite. It calls generate_report() to render the HTML report.

Parameters

test (Union[unittest.TestCase, unittest.TestSuite]) – test case or test suite

Returns

an HTML test result

Return type

HTMLTestResult

generate_report(result: html_reporter.result.HTMLTestResult) None[source]

Render the HTML report using self.template template file. The following variables are available to the template:

  • title: HTML page title

  • description: description of the report

  • result: the HTMLTestResult object

  • start_time: start time of the test run

  • stop_time: stop time of the test run

  • test_groups: list of test groups

    (type: List[TestGroupReport])

Parameters

result (HTMLTestResult) – the HTMLTestResult object

generate_report_table(result: html_reporter.result.HTMLTestResult) List[TestGroupReport][source]

Generate a list of test group reports.

Parameters

result (HTMLTestResult) – the HTMLTestResult object

Returns

list of test group reports

Return type

List[TestGroupReport]

generate_test_case_report(cid: int, tid: int, test_case_result: html_reporter.result.TestCaseResult) TestCaseReport[source]

Generate a test case report.

Parameters
  • cid (int) – test group index

  • tid (int) – test case index

  • test_case_result (TestCaseResult) – test case result

Returns

test case report

Return type

TestCaseReport