A good mock library for python
Project description
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.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file goodmock-0.0.1.tar.gz.
File metadata
- Download URL: goodmock-0.0.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d5b414ba82593c2aa3d15b09d4bbc3e7fce7df62607598c3c422ac5048d4f1f
|
|
| MD5 |
57d1bab6e2dcf334a5662db48d1138b8
|
|
| BLAKE2b-256 |
a665b24c9d7c71f72eb899ec301c26cd1426ab592471a1d2b45072f1cc7228ac
|
File details
Details for the file goodmock-0.0.1-py3-none-any.whl.
File metadata
- Download URL: goodmock-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21bf3f99c10ef4300ac18a08c9f1e9ea3cae46841eb0a5886c5cf9a12f01f56b
|
|
| MD5 |
ecd1cd5872bebe93cfa2d6682154453a
|
|
| BLAKE2b-256 |
7750f697df8b4b7a077311c0e5fd3eba47de5052b6661b6fc167f3ce1846e7af
|