auto-pytest-mg-0.8.0
توضیحات
Awesome `auto_pytest_mg` is a Python cli/package created with https://github.com/TezRomacH/python-package-template
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | auto-pytest-mg-0.8.0 |
| نام | auto-pytest-mg |
| نسخه کتابخانه | 0.8.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | auto_pytest_mg |
| ایمیل نویسنده | ryan.ozelie@gmail.com |
| آدرس صفحه اصلی | https://github.com/auto_pytest_mg/auto_pytest_mg |
| آدرس اینترنتی | https://pypi.org/project/auto-pytest-mg/ |
| مجوز | MIT |
# auto_pytest_mg (Automatic pytest Mock Generator)
<div align="center">
[](https://pypi.org/project/auto_pytest_mg/)
[](https://github.com/psf/black)

[](https://github.com/rozelie/auto_pytest_mg/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Aapp%2Fdependabot)
[](https://github.com/psf/black)
[](https://pypi.org/project/auto-pytest-mg/)
</div>
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
- `mocker`: [pytest-mock](https://pypi.org/project/pytest-mock/)
- `mg`: [pytest-mocker-generator](https://github.com/pksol/pytest-mock-generator)
- If you're unfamiliar with pytest-mock-generator, you can read up on usage information in their [README](https://github.com/pksol/pytest-mock-generator#readme).
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.
## Usage
```bash
# 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`
```python
# 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:
```python
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](https://pynguin.readthedocs.io/en/latest/)
- Executes given source code and uses a genetic algorithm to produce test cases
- Can output to unittest/pytest test styles
- [pythoscope](https://github.com/mkwiatkowski/pythoscope)
- Last updated in 2016
- Performs static analysis, does not run your code.
- Outputs unittest test style only
## Development
See [DEVELOPMENT.md](./DEVELOPMENT.md)
## License
This project is licensed under the terms of the `MIT` license. See [LICENSE](https://github.com/rozelie/auto_pytest_mg/blob/master/LICENSE) for more details.
## Credits [](https://github.com/TezRomacH/python-package-template)
This project was generated with [`python-package-template`](https://github.com/TezRomacH/python-package-template)
نیازمندی
| مقدار | نام |
|---|---|
| >=4.5.0,<5.0.0) | importlib_metadata |
| >=0.4.0,<0.5.0 | typer[all] |
| >=12.4.4,<13.0.0 | rich |
| >=0.5.1,<0.6.0 | inflection |
| >=5.10.1,<6.0.0 | isort |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7,<4.0 | Python |
نحوه نصب
نصب پکیج whl auto-pytest-mg-0.8.0:
pip install auto-pytest-mg-0.8.0.whl
نصب پکیج tar.gz auto-pytest-mg-0.8.0:
pip install auto-pytest-mg-0.8.0.tar.gz