Skip to main content

A more readable text output for Python's built in unittest framework

Project description

Better PyUnit Format

A more readable text output for Python's built in unittest framework

Overview

This package provides an implementation of a test runner and a test result for the Python unittest package.

This package simply creates an override of the built-in TextTestRunner that removes all the formatting that it does by default and only runs the test suite. This means that this test runner passes all formatting responsibility on to the test result.

The test result that this package provides formats the output of the test in a much more readable way to make interpreting unit test results a bit easier for introductory students.

This package is targeted towards students and education and was built with that limited use case in mind. With that said, please, feel free to use this in your applications and tell me what you think!

Using Better PyUnit Format

  1. Install the package via pip with pip install Better-PyUnit-Format
  2. Import the BetterPyUnitTestRunner
  3. Run your testsuite!

Example code

# run.py

import unittest
import test
from BetterPyUnitFormat import BetterPyUnitTestRunner

if __name__ == "__main__":
    testSuite = unittest.loader.makeSuite(test.Test)
    runner = BetterPyUnitTestRunner()
    runner.run(testSuite)

Example Execution

# test.py

import unittest


class Test(unittest.TestCase):
    def test_failure(self):
        """This test should fail"""
        self.assertEquals(1, 2)

    def test_success(self):
        """This test should pass"""
        self.assertEquals(1, 1)

    def test_error(self):
        """This test will error"""
        0/0

    @unittest.skip("Skipping this test :)")
    def test_skip(self):
        """This test will be skipped"""
        self.assertEquals(1, 2)
====================
--------------------
[ RUN      ] This test will error (test.Test.test_error)
[    ERROR ] This test will error
A(n) ZeroDivisionError occurred:
[ZeroDivisionError] division by zero

-------------------- 

--------------------
[ RUN      ] This test should fail (test.Test.test_failure)
[     FAIL ] This test should fail
Failure reason:
1 != 2

-------------------- 

--------------------
[ RUN      ] This test will be skipped (test.Test.test_skip)
[     SKIP ] This test will be skipped
Skip Reason: Skipping this test :)
-------------------- 

--------------------
[ RUN      ] This test should pass (test.Test.test_success)
[       OK ] This test should pass
-------------------- 

====================
[  FAILED  ] 
1 tests passed.
1 tests failed.
1 tests errored.
1 tests skipped.
1 / 4
====================

License

This package is licensed under the Unlicense. Feel free to use it for any purpose commercial or non-commercial.

Project details


Download files

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

Source Distribution

Better-PyUnit-Format-0.2.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

Better_PyUnit_Format-0.2.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file Better-PyUnit-Format-0.2.0.tar.gz.

File metadata

  • Download URL: Better-PyUnit-Format-0.2.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for Better-PyUnit-Format-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4e2d567d0ff564210e65dd257aec211feaea10501823b9731f44ff596896840f
MD5 995a9223662f7fde663601e18c84c853
BLAKE2b-256 6d08ae5ecf2fe5069ab62ff567affd54f97e99e99ad6434d5d41db08eba33c32

See more details on using hashes here.

File details

Details for the file Better_PyUnit_Format-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for Better_PyUnit_Format-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 635320708cfddcba801b25a4b142d2117b3dbcb60cdce1b2a17f2f94bcfe79a7
MD5 bcc2c1be4dfe4ac193d74ed9b4a2e730
BLAKE2b-256 66c705201f91fe0de4b1bed48287bea10f3248095ce69b406648e26822bba62f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page