Skip to main content

Auto generate unit test templates

Project description

gutt

Auto Generate Unit Test Templates

Install

$ pip install gutt

Basic Usage

Assume you have a package, and its layout:

my_awesome_package
├── __init__.py
└── module1.py

some codes inside my_awesome_package/module1.py:

import sys

MY_CONST = 123

def funcion1():
    pass


def function2():
    pass


class MyObject:
    def method1(self):
        pass

    @classmethod
    def classmethod1(cls):
        pass

    @staticmethod
    def staticmethod1():
        pass

gutt can generate unit testing templates for all implementations in just one line:

$ gutt -m my_awesome_package -o mytests

The output layout:

mytests
├── __init__.py
└── my_awesome_package
    ├── __init__.py
    └── test_module1.py

The unit test templates inside test_module1.py

def test_funcion1():
    from my_awesome_package.module1 import funcion1

    assert funcion1


def test_function2():
    from my_awesome_package.module1 import function2

    assert function2


class TestMyObject:
    @classmethod
    def setup_class(cls):
        from my_awesome_package.module1 import MyObject

        assert MyObject

    @classmethod
    def teardown_class(cls):
        pass

    def setup_method(self, method):
        pass

    def teardown_method(self, method):
        pass

    def test_method1(self):
        pass

    def test_classmethod1(self):
        pass

    def test_staticmethod1(self):
        pass

Each module in source codes maps to a testing module(module1.py --> test_module1.py), and each function, each class and all methods inside that class maps to corresponding test templates.

  • gutt will skip code generation if the test templates for the functions already exist.
  • gutt won't delete the corresponding test templates if the source codes get deleted or renamed.
  • For new added codes: modules, functions or methods inside class, just re-run gutt to generate new test templates for them.

Run unit test with pytest, for example:

$ pytest --doctest-modules --cov=my_awesome_package mytests

=============================== test session starts ===============================
platform linux -- Python 3.8.8, pytest-4.6.11, py-1.10.0, pluggy-0.13.1
rootdir: /home/ryan/Workspace/my_awesome_package
plugins: mock-1.13.0, cov-2.11.1
collected 5 items                                                                 

mytests/my_awesome_package/test_module1.py .....                            [100%]

----------- coverage: platform linux, python 3.8.8-final-0 -----------
Name                             Stmts   Miss  Cover
----------------------------------------------------
my_awesome_package/__init__.py       0      0   100%
my_awesome_package/module1.py       13      5    62%
----------------------------------------------------
TOTAL                               13      5    62%


============================ 5 passed in 0.07 seconds =============================

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

gutt-1.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gutt-1.2.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file gutt-1.2.0.tar.gz.

File metadata

  • Download URL: gutt-1.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.20.1 CPython/3.8.5 Linux/4.15.0-213-generic

File hashes

Hashes for gutt-1.2.0.tar.gz
Algorithm Hash digest
SHA256 12f434dfbbd5b4c0e3222c0e1c1810ea6e0a5d86117b482214414313880acbd7
MD5 9d1369e70fa10badb594f2aaa5e6cb71
BLAKE2b-256 b83733225b3e606f7c4d73157e1449b06383a2e433dc3d41584c3e92b875199a

See more details on using hashes here.

File details

Details for the file gutt-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: gutt-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.20.1 CPython/3.8.5 Linux/4.15.0-213-generic

File hashes

Hashes for gutt-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58e84719418e3036e300aaf2003320864cc72f18b0f01ba99ca79cec7bc91202
MD5 51faea72310d254dcc0941f351d6c067
BLAKE2b-256 f0294a813bef7614feb70b8ae2f4f70010f756e981c3709924c9977294845c9e

See more details on using hashes here.

Supported by

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