Mock

Mocking and Testing Library
Download

Mock Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Michael Foord
  • Publisher web site:
  • http://www.voidspace.org.uk/python/rest2web/

Mock Tags


Mock Description

Mocking and Testing Library Mock is a simple class for mocking in unit tests.mock provides a core Mock class that is intended to reduce the need to create a host of trivial stubs throughout your test suite. After performing an action, you can make assertions about which methods / attributes were used and arguments they were called with. You can also specify return values and set needed attributes in the normal way.It also provides a mock.patch() decorator that handles patching module and class level attributes within the scope of a test, along with mock.sentinel for creating unique objects.Most mocking libraries follow the ‘record -> replay’ pattern of mocking. I prefer the ‘action -> assertion’ pattern, which is more readable and intuitive; particularly when working with the Python unittest module. For a discussion of the merits of the two approaches, see Mocking, Patching, Stubbing: all that Stuff. Requirements: · Python What's New in This Release: · Made DEFAULT part of the public api. · Documentation built with Sphinx. · side_effect is now called with the same arguments as the mock is called with and if returns a non-DEFAULT value that is automatically set as the mock.return_value. · wraps keyword argument used for wrapping objects (and passing calls through to the wrapped object). · Mock.reset renamed to Mock.reset_mock, as reset is a common API name. · patch / patch_object are now context managers and can be used with with. · A new ‘create’ keyword argument to patch and patch_object that allows them to patch (and unpatch) attributes that don’t exist. (Potentially unsafe to use - it can allow you to have tests that pass when they are testing an API that doesn’t exist - use at your own risk!) · The methods keyword argument to Mock has been removed and merged with spec. The spec argument can now be a list of methods or an object to take the spec from. · Nested patches may now be applied in a different order (created mocks passed in the opposite order). This is actually a bugfix. · patch and patch_object now take a spec keyword argument. If spec is passed in as ‘True’ then the Mock created will take the object it is replacing as its spec object. If the object being replaced is a class, then the return value for the mock will also use the class as a spec. · A Mock created without a spec will not attempt to mock any magic methods / attributes (they will raise an AttributeError instead).


Mock Related Software