Powerful mocks with complete specs
Project description
spec_mock
Create Mocks which completely mimic the real deal!
spec_mock act just like the rea deal!
- spec_mock won't let you use the mock in ways a real instance wouldn't allow.
- When the class changes so will your mock!
For example:
from spec_mock import spec_mock
class Person:
def __init__(self, name: str, age: int):
self.name = name
self.age = age
def talk(self):
pass
person = spec_mock(Person)
_ = person.age # Valid
_ = person.name # Valid
_ = person.talk.side_effect = lambda: print("hi") # Valid
_ = person.gender # Invalid!
How is this different from MagicMock?
MagicMock(spec=) and create_autospec don't mock the attributes:
person = MagicMock(spec=Person)
_ = person.age # AttributeError: Mock object has no attribute 'age'
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
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 spec_mock-1.0.1-py3-none-any.whl.
File metadata
- Download URL: spec_mock-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
538be6237be1a220d2614409e03b8de07d3c3907c30fe0106fcf882aca5a0d4e
|
|
| MD5 |
c1e66fcf8c5cec9ddd7d9312686858cb
|
|
| BLAKE2b-256 |
c1fa237471756b5baf21b165e3a308afa7d45de9ae8cb07a1ffeec4e6e585287
|