Skip to main content

A unit test runner for Python, and generate HTML reports.

Project description

# PyUnitReport

PyUnitReport is a unittest test runner that save test results in Html files, for human readable presentation of results.

## Installation

$ pip install PyUnitReport

## Usage

### testcase

from pyunitreport import HTMLTestRunner
import unittest

class TestStringMethods(unittest.TestCase):
""" Example test for HtmlRunner. """

def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')

def test_isupper(self):

def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):

def test_error(self):
""" This test should be marked as error one. """
raise ValueError

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

@unittest.skip("This is a skipped test.")
def test_skip(self):
""" This test should be skipped. """

if __name__ == '__main__':

In most cases, you can use `PyUnitReport` with `unittest.main`, just pass it with the `testRunner` keyword.

For `HTMLTestRunner`, the only parameter you must pass in is `output`, which specifies the directory of your generated report. Also, if you want to specify the report name, you can use the `report_name` parameter, otherwise the report name will be the datetime you run test. And if you want to run testcases in `failfast` mode, you can pass in a `failfast` parameter and assign it to be True.

Here is another way to run the testcases.

from pyunitreport import HTMLTestRunner

kwargs = {
"output": output_folder_name,
"report_name": report_name,
"failfast": True
result = HTMLTestRunner(**kwargs).run(task_suite)

### testsuite

For those who have `test suites` it works too, just create a runner instance and call the run method with your suite.

Here is an example:

from unittest import TestLoader, TestSuite
from pyunitreport import HTMLTestRunner
import ExampleTest
import Example2Test

example_tests = TestLoader().loadTestsFromTestCase(ExampleTests)
example2_tests = TestLoader().loadTestsFromTestCase(Example2Test)

suite = TestSuite([example_tests, example2_tests])
kwargs = {
"output": output_folder_name,
"report_name": report_name,
"failfast": True
runner = HTMLTestRunner(**kwargs)

## Output

### Console output

This is an example of what you got in the console.

$ python examples/

Running tests...
This test should be marked as error one. ... ERROR (0.000575)s
This test should fail. ... FAIL (0.000564)s
test_isupper (__main__.TestStringMethods) ... OK (0.000149)s
This test should be skipped. ... SKIP (0.000067)s
test_split (__main__.TestStringMethods) ... OK (0.000167)s
test_upper (__main__.TestStringMethods) ... OK (0.000134)s

ERROR [0.000575s]: This test should be marked as error one.
Traceback (most recent call last):
File "examples/", line 23, in test_error
raise ValueError

FAIL [0.000564s]: This test should fail.
Traceback (most recent call last):
File "examples/", line 27, in test_fail
self.assertEqual(1, 2)
AssertionError: 1 != 2

Ran 6 tests in 0.002s

(Failures=1, Errors=1, Skipped=1)

Generating HTML reports...
Template is not specified, load default template instead.
Reports generated: /Users/Leo/MyProjects/ApiTestEngine/src/pyunitreport/reports/example_dir/2017-07-26-23-33-49.html

### Html Output

![html output](docs/html_output.gif)

![html output](docs/html_output.png)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for PyUnitReport, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size pyunitreport-0.1.4-py3.3.egg (20.2 kB) File type Egg Python version 3.3 Upload date Hashes View
Filename, size pyunitreport-0.1.4.tar.gz (10.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page