Giter Club home page Giter Club logo

bupytest's Introduction

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.

bupytest's People

Contributors

jaedsonpys avatar

Watchers

 avatar

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.