goodmock - A Good Mock Library for Python
This repository is for activate development of goodmock.
Disclaimer
This module makes no claims of mock magic, but it's good
Getting Started
All source code for this project is located in goodmock.py
Prerequisites
goodmock relies on features introduced in PEP 612, and only supports Python 3.10+
Installation
PyPi: TODO
Manual Installation: navigate to the root directory of the project and run python -m pip install .
How to use goodmock
Given a class definition like:
class ClassA:
def method(int i) -> int: ...
You can set a return value for a class method:
classa_mock = Mock.of(ClassA)
Mock.when(classa_mock.method).takes(1).returns = 2
assert classa_mock.method(1) == 2
Or you can set an expected exception for a class method:
classa_mock = Mock.of(ClassA)
Mock.when(classa_mock.method).takes(1).raises = Exception()
with pytest.raises(Exception):
classa_mock.method(1)
That's it!
Need help?
- For more examples see the unit tests
- File an issue via Github Issues
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution.
Release files for goodmock 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| goodmock-0.0.1.tar.gz | 10.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| goodmock-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.4 kB
Release files / goodmock-0.0.1.tar.gz
| Download URL | goodmock-0.0.1.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d5b414ba82593c2aa3d15b09d4bbc3e7fce7df62607598c3c422ac5048d4f1f
|
|
BLAKE2b-256 checksum How to use checksums |
a665b24c9d7c71f72eb899ec301c26cd1426ab592471a1d2b45072f1cc7228ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Release files / goodmock-0.0.1-py3-none-any.whl
| Download URL | goodmock-0.0.1-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21bf3f99c10ef4300ac18a08c9f1e9ea3cae46841eb0a5886c5cf9a12f01f56b
|
|
BLAKE2b-256 checksum How to use checksums |
7750f697df8b4b7a077311c0e5fd3eba47de5052b6661b6fc167f3ce1846e7af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|