Skip to main content

Perform fast and detailed unit tests with BuPyTest.

Project description

BuPyTest - Unit Tests

BuPyTest is a library to perform unit tests on your code by classes. You can create tests using classes and run them together in a single file.

With bupytest, you can implement git hooks to automatically run tests using Command Line.

  • Test multiple files using command line;
  • Test only one file using command line;
  • Test multiple classes in one file;
  • Test using command line.

You can install the latest version of BuPyTest using the pip package manager:

pip install bupytest

How to use

Here's a simple tutorial on how to use bupytest in your tests:

In the base class bupytest.BaseTest all tests are executed in the order they were defined (sequential).

import bupytest


class TestFoo(bupytest.UnitTest):
    def __init__(self):
        super().__init__()

    def test_1(self):
        self.assert_true(True, message='A error ocurred')

    def test_2(self):
        false_value = ''
        self.assert_false(false_value, message='Empty string')


if __name__ == '__main__':
    bupytest.this()

With bupytest, you define test classes and the methods, which will be tested. To test a value, you can use the following methods of the bupytest.UnitTest class:

  • UnitTest.assert_true: asserts a true value;
  • UnitTest.assert_false: asserts a false value;
  • UnitTest.assert_expected: asserts an expected value.

All test classes must start with "Test", and all test class methods must start with "test_".

At the end of the file, the bupytest.this method runs the test in this file. That is, all test classes in this file will be executed.

You can also define several other classes in the same file for testing:

import bupytest


class TestFoo(bupytest.UnitTest):
    def __init__(self):
        super().__init__()

    def test_1(self):
        self.assert_true(True, message='A error ocurred')

    def test_2(self):
        false_value = ''
        self.assert_false(false_value, message='Empty string')


class TestBar(bupytest.UnitTest):
    def __init__(self):
        super().__init__()

    def test_1(self):
        self.assert_expected('hello', 'hello')


if __name__ == '__main__':
    bupytest.this()

Command Line

bupytest also has a command line application available to run tests, the script is called bupytest, see some commands and flags (use --help to get help):

Just use the test command to test one module or a directory with multiple modules. Here is an example:

bupytest test test_cookiedb.py

Now testing multiple test modules inside a directory:

bupytest test tests/

To test multiple modules from a directory, as in the example above, the name of the modules to be tested must start with test_, otherwise the test **will not run.

License

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

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

bupytest-1.3.1.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file bupytest-1.3.1.tar.gz.

File metadata

  • Download URL: bupytest-1.3.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.28.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for bupytest-1.3.1.tar.gz
Algorithm Hash digest
SHA256 6d71ee44ce2d3c8dbb4f22c31d23a9dd0a8fd5eb0c78b8df56c7ab8667e20598
MD5 c39ac87607cad170d3b03cccf74e2442
BLAKE2b-256 f38e76b5e8e65dc5bc7fb265ab7057185d40ede2d5ef9594bd0c64547a24a4be

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