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

Uploaded Source

Built Distribution

gutt-1.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gutt-1.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.8.5 Linux/4.15.0-211-generic

File hashes

Hashes for gutt-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6e3da89a1200e4478c3a871f853ce69c807010cb77018631e397a6045b1f37f1
MD5 f6e7db06b6bf9f7980f40290ffdae5c3
BLAKE2b-256 d59ae24f714f726d778ac97d4e2c57d910d2042d88dfa7e2b39d13d10af8719e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gutt-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.8.5 Linux/4.15.0-211-generic

File hashes

Hashes for gutt-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ef42cfe3c9d5d25bcd0c7a5b54081ce2750a719c86394f9b53dba5f28129d9c
MD5 f5e1185f6fd28635dcdd1a86468bc3fe
BLAKE2b-256 959eae94f572f06327888d787959b05a2afe504bb9d6d2a43b3cd1c6886a5ef5

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