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'
Release files for spec-mock 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spec_mock-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / spec_mock-1.0.1-py3-none-any.whl
| Download URL | spec_mock-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
538be6237be1a220d2614409e03b8de07d3c3907c30fe0106fcf882aca5a0d4e
|
|
BLAKE2b-256 checksum How to use checksums |
c1fa237471756b5baf21b165e3a308afa7d45de9ae8cb07a1ffeec4e6e585287
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.7
|