Skip to main content

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


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

spec_mock-1.0.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page