Awesome `auto_pytest_mg` is a Python cli/package created with https://github.com/TezRomacH/python-package-template
Project description
auto_pytest_mg (Automatic pytest Mock Generator)
- GitHub: https://github.com/rozelie/auto_pytest_mg
- GitHub Releases: https://github.com/rozelie/auto_pytest_mg/releases
- PyPi: https://pypi.org/project/auto-pytest-mg/
auto_pytest_mg parses the AST of an input python file to generate a new test file with boilerplate
test functions. Rendered tests include the mocker
and mg
fixtures which are available via the
pytest-mock and pytest-mocker-generator
packages, respectively.
Note that this packages is a static analysis tool and will not execute any of your code.
Usage
# 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/my_file.py
Example
Source file located at my_project/my_file.py
# my_project/my_file.py
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/my_file.py
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"
@pytest.fixture
def mock_requests(mocker):
return mocker.patch(f"{MODULE_PATH}.requests")
@pytest.fixture
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):
mg.generate_uut_mocks_with_asserts(my_class.method)
result = my_class.method()
def test_get(mocker, mg):
url = mocker.MagicMock()
mg.generate_uut_mocks_with_asserts(get)
result = get(url=url)
Similar packages
- pyguin
- Runs given 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.
Development
See DEVELOPMENT.md
License
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.](https://pypi-camo.freetls.fastly.net/06759df61ed58ed0d117ce78b7d8db438e70127f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f707974686f6e2d2d7061636b6167652d2d74656d706c6174652d2546302539462539412538302d627269676874677265656e)
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
Built Distribution
Hashes for auto_pytest_mg-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac7a271e5125b2058a3eb51cb4cebe5344091e1811354a0b3295ca8bcb2a6088 |
|
MD5 | 40f7959a1f77e0adea4788c1a9195002 |
|
BLAKE2b-256 | 16c776d21effe233bc08d9cb8ab1b96e9bc79e3d89c623ce3131c3ed2b4ebfb5 |