Skip to main content

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'

Metadata

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)

Table of built distributions (wheels) for spec-mock 1.0.1
File Interpreter ABI Platform Actions
spec_mock-1.0.1-py3-none-any.whl Python 3 none any Details for spec_mock-1.0.1-py3-none-any.whl

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

Security for spec-mock 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page