Skip to main content

python ut test code generator.

Project description

Python UT generator

This tools generate automatically Python pytest Unit test code.
This project uses ast module to generate.
Easy to make coverage test. And Easy to customize test code.

Feature

  • Generate unit test python file in tests package.
  • Generate pytest test function from each function.
  • Generate mock patch syntax code.
  • Generate argument syntax code to call.
  • If function has return value, create assert return.

Installation

Install pip

pip install pyutgenerator

https://pypi.org/project/pyutgenerator/

Run tool.

Genarete test code

pyutgen "Input File Name"

or

python -m pyutgenerator.run "Input File Name"

Sample input file

import os


def aaaaa():
    """
    call and return
    """
    return os.path.exists('')

Sample out put


import pytest
from unittest.mock import patch
from unittest.mock import MagicMock

from tests.pyutgenerator.data import pattern01

def test_aaaaa():
    # plan

    # do
    with\
            patch('tests.pyutgenerator.data.pattern01.os.path') as m1:
        m1.return_value = None
        m1.exists = MagicMock(return_value=None)
        ret = pattern01.aaaaa()

        # check
        assert ret

For the future

  • For Code
    • Genarete various parameters for test.
    • Write return check value.
    • 'exception' check.
    • 'with' description mock.
    • Generate test data.
    • Assertion for method call for count, parameter, throw.
    • parameter type for str,list, obj ...
    • Simple code analyst report. like no None check or Parameter
    • For django
  • Customize parameter options or setting file.
    • Exclude function mock.
    • Source directory path.
    • tab space num.
  • Get test data from debug.
  • able to run default generated code and pass test.
  • Full coverage.
  • web ui for test.

Prerequisites

not yet

not yet

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc

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

pyutgenerator-0.12.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

pyutgenerator-0.12.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file pyutgenerator-0.12.0.tar.gz.

File metadata

  • Download URL: pyutgenerator-0.12.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.12 Windows/10

File hashes

Hashes for pyutgenerator-0.12.0.tar.gz
Algorithm Hash digest
SHA256 a5136119635a74bbec5b87a586ad69fb9eea371fa1a48dd468ebc015db0da185
MD5 8b237399ead0baf86ae81f22ff67347a
BLAKE2b-256 c2415e7f04ba0575f517092e6fb84ce393ba2b10d388617ac6962bed8f378240

See more details on using hashes here.

File details

Details for the file pyutgenerator-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: pyutgenerator-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.12 Windows/10

File hashes

Hashes for pyutgenerator-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 083fb78122be47bd91dd6b25ae622db404ded9f903122b0d73db237114cf9b79
MD5 73839d6718a0e3d890f061602ca77815
BLAKE2b-256 27def1ba8be155bd66f991dc9bbcbdeae6c9f67505f05f83f57968422b0ad7f7

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