Skip to main content

Generate pytest tests from your Python source files.

Project description

Getting tired of manually writing unit test stubs for your Python code? Easy.


# file:
def testable_func(arg_one, arg_two):

class AClass:
    def __init__(self, some, constructor, params):

    def testable_func_in_class(self, an_arg):
$ pytestgen
# file:
import pytest

import example

        # TODO: fill in test data for test_testable_func
        # pytest.param(, , id="")
def test_testable_func(arg_one, arg_two, expected):
    # TODO: create assertions for test_testable_func
    # example.testable_func(arg_one, arg_two)

        # TODO: fill in test data for test_aclass_testable_func_in_class
        # pytest.param(example.AClass(some, constructor, params), , expected, id="")
def test_aclass_testable_func_in_class(instance, an_arg, expected):
    # TODO: write test for test_aclass_testable_func_in_class
    # TODO: create assertions for test_aclass_testable_func_in_class
    # instance.testable_func_in_class(an_arg)


$ pip install pytestgen


# generate tests for directory 'my_package' in 'tests/' directory
$ pytestgen my_package

# generate tests for some python files and directory 'the_package'
$ pytestgen the_package

# generate tests for directory 'cool_app' in 'cool_tests/' directory
$ pytestgen cool_app -o cool_tests

# generate tests for functions 'foo' and 'bar' in ''
$ pytestgen -i foo -i bar

Full usage text

Usage: pytestgen [OPTIONS] PATH...

  Generate pytest unit tests from your Python source code.

  -o, --output-dir PATH  The path to generate tests in.  [default: tests]
  -i, --include FUNC     Function names to generate tests for. You can use
                         this multiple times.
  -h, --help             Show this message and exit.



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

pytestgen-0.1.1.tar.gz (8.8 kB view hashes)

Uploaded source

Built Distribution

pytestgen-0.1.1-py3-none-any.whl (10.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page