Skip to main content

Awesome `auto_pytest_mg` is a Python cli/package created with

Project description

auto_pytest_mg (Automatic pytest Mock Generator)

Python Version Code style: black Coverage Report Dependencies Status

GitHub PyPi

auto_pytest_mg generates a test skeleton for a given python file. This skeleton includes:

  • fixtures that mock all non-standard library imported names
  • a boilerplate test for every class method and property
  • a boilerplate test for every function
  • mocker and mg fixtures for all tests

It is not auto_pytest_mg's goal to produce the entirety of the test. The creation of test mocks and asserts is delegated to pytest-mocker-generator via the mg fixture and the mg.generate_uut_mocks_with_asserts(...) call.

This package is a static analysis tool and will not execute any of your code.


# install the package
pip install auto_pytest_mg

# go to project's source root
cd my_project

# pass the file to generate tests for
auto_pytest_mg my_project/


Source file located at my_project/

# my_project/
import requests

class MyClass:

    def __init__(self, a: int):
        self.a = a

    def method(self) -> int:
        return self.a

def get(url: str) -> requests.Response:
    return requests.get(url)

Running auto_pytest_mg my_project/ will then output to stdout the generated test file:

import pytest

from my_project.my_file import get, MyClass

MODULE_PATH = "my_project.my_file"

def mock_requests(mocker):
    return mocker.patch(f"{MODULE_PATH}.requests")

def my_class(mocker):
    a = mocker.MagicMock()
    return MyClass(a=a)

class TestMyClass:
    def test__init__(self, mocker):
        a = mocker.MagicMock()

        my_class_ = MyClass(a=a)

    def test_method(self, mocker, mg, my_class):

        result = my_class.method()

def test_get(mocker, mg):
    url = mocker.MagicMock()

    result = get(url=url)

Similar packages

  • pyguin
    • Executes given source code and uses a genetic algorithm to produce test cases
    • Can output to unittest/pytest test styles
  • pythoscope
    • Last updated in 2016
    • Performs static analysis, does not run your code.
    • Outputs unittest test style only




This project is licensed under the terms of the MIT license. See LICENSE for more details.

Credits 🚀 Your next Python package needs a bleeding-edge project structure.

This project was generated with python-package-template

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

auto_pytest_mg-0.8.0.tar.gz (11.6 kB view hashes)

Uploaded Source

Built Distribution

auto_pytest_mg-0.8.0-py3-none-any.whl (12.7 kB view hashes)

Uploaded Python 3

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