HTML Test Runner

1.2.1 · maintenance · verified Thu Apr 16

html-testRunner is a Python unittest test runner that generates human-readable HTML reports for test results. It extends the standard library's unittest module to provide clear and organized visual output. The current version is 1.2.1, released in September 2019. The project currently has an infrequent release cadence, with the latest update several years ago, and is considered to be in a maintenance state.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic `unittest.TestCase` suite and run it using `HtmlTestRunner.HTMLTestRunner` to generate an HTML report. The report will be saved in a 'reports' directory, which is created if it doesn't exist.

import unittest
from HtmlTestRunner import HTMLTestRunner
import os

class MyTests(unittest.TestCase):
    def test_success_case(self):
        """This test should pass."""
        self.assertEqual(1, 1)

    def test_failure_case(self):
        """This test should fail."""
        self.assertEqual(1, 2)

    def test_error_case(self):
        """This test should raise an error."""
        raise ValueError("Deliberate error for testing")

    @unittest.skip("demonstrating skipping")
    def test_skipped_case(self):
        """This test should be skipped."""
        self.fail("Should not run")

if __name__ == '__main__':
    # Ensure a 'reports' directory exists
    output_dir = 'reports'
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(MyTests))

    # Run the test suite with HTMLTestRunner
    runner = HTMLTestRunner(output=output_dir, report_name="MyTestReport")
    runner.run(suite)
    print(f"HTML report generated in {output_dir}/MyTestReport.html")

view raw JSON →