Giter Site home page Giter Site logo

phongnt570 / html-reporter Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 1.36 MB

Render Python unittest results in nice HTML files

Home Page: https://html-reporter.readthedocs.io

License: MIT License

Makefile 7.30% Python 63.29% HTML 29.40%
python test-runner testrunner unittest html-testrunner test-reporting test-tools htmltestrunner

html-reporter's Introduction

html-reporter

Documentation Status License Supported Python Versions

What is html-reporter?

html_reporter.HTMLTestRunner is a Python test runner for use with its unittest framework. After running the test cases, it generates a report in an HTML file to show the results in a nice, human-readable way. This package was inspired by HTMLTestRunner.py written by Wai Yip Tung and began with transforming the old code to use Jinja2 template and adopting Bootstrap 5 CSS.

html_reporter could be useful in programming classes, where teachers/lectures want to show the test results of students' code, or for anyone who wants to see a nicer test report than the boring terminal output.

Following is an example of the output HTML file:

Test Results

Getting started

Prerequisites

html-reporter requires Python 3.7 or later.

Install

Install the package via pip:

$ pip install html-reporter

Usage

HTMLTestRunner is a counterpart to unittest.TextTestRunner. Instantiate an HTMLTestRunner object and use it to run your test suite.

Example using unittest.main:

import unittest
from html_reporter import HTMLTestRunner

# define your test cases

# output to a file
if __name__ == "__main__":
    runner = HTMLTestRunner(
        report_filepath="my_report.html",
        title="My unit test",
        description="This demonstrates the report output by HTMLTestRunner.",
        open_in_browser=True
    )

    # run the test
    unittest.main(testRunner=runner)

Example using unittest.TestSuite:

import unittest
from html_reporter import HTMLTestRunner

# define your test cases

# output to a file
if __name__ == "__main__":
    my_test_suite = unittest.TestSuite()  # define your test suite
    # add your test cases:
    # my_test_suite.addTest(...)

    runner = HTMLTestRunner(
        report_filepath="my_report.html",
        title="My unit test",
        description="This demonstrates the report output by HTMLTestRunner.",
        open_in_browser=True
    )

    # run the test
    runner.run(my_test_suite)

TODO

  • [x] Switch to Jinja2 template
  • [x] Refactor
  • [x] Add support for skipped tests
  • [x] Release pypi package
  • [ ] Option for combine/separate report files
  • [ ] Add tests
  • [ ] Improve documentations

Credits

html-reporter's People

Contributors

phongnt570 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

html-reporter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.