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.3.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file better_pyunit_format-0.2.3.tar.gz.

File metadata

  • Download URL: better_pyunit_format-0.2.3.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for better_pyunit_format-0.2.3.tar.gz
Algorithm Hash digest
SHA256 99a3196905d620032299e2d409adc2a34d0f39819e5cdf9518c529c9b00f6133
MD5 0c4d9d0ede6f23b24d4606dc28e01133
BLAKE2b-256 7a919c9d469576b4b53d60dae89ee183a2fc41448233c7e7069fce38e40a9f3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for Better_PyUnit_Format-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 54f8ca8ca3c878a7396e1a3b3363dd834073b5d242ccb233eb823aaabc5334a0
MD5 fbe2f6aff37eec57e72a16332be901cf
BLAKE2b-256 d20c0e935006215572020e7a661454ac97096765f41c870cb06c0e9b37a6a65f

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