[TIP] mock 1.0 beta 1

Michael Foord michael at voidspace.org.uk
Fri Jul 13 08:46:40 PDT 2012

Hey all,

mock 1.0 beta 1 has now been released. This matches unittest.mock in Python 3.3 beta 1.

You can see a changelog of all bug fixes and new features here:


Download from PyPI:


mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects.

Changes to mock since 0.8:

2012/07/13 Version 1.0.0 beta 1

* Added `patch.stopall` method to stop all active patches created by `start`
* BUGFIX: calling `MagicMock.reset_mock` wouldn't reset magic method mocks
* BUGFIX: calling `reset_mock` on a `MagicMock` created with autospec could
  raise an exception

2012/05/04 Version 1.0.0 alpha 2

* `PropertyMock` attributes are now standard `MagicMocks`
* `create_autospec` works with attributes present in results of `dir` that
  can't be fetched from the object's class. Contributed by Konstantine Rybnikov
* Any exceptions in an iterable `side_effect` will be raised instead of
* In Python 3, `create_autospec` now supports keyword only arguments

2012/03/25 Version 1.0.0 alpha 1

The standard library version!

* `mocksignature`, along with the `mocksignature` argument to `patch`, removed
* Support for deleting attributes (accessing deleted attributes will raise an
* Added the `mock_open` helper function for mocking the builtin `open`
* `__class__` is assignable, so a mock can pass an `isinstance` check without
  requiring a spec
* Addition of `PropertyMock`, for mocking properties
* `MagicMocks` made unorderable by default (in Python 3). The comparison
  methods (other than equality and inequality) now return `NotImplemented`
* Propagate traceback info to support subclassing of `_patch` by other
* BUGFIX: passing multiple spec arguments to patchers (`spec` , `spec_set` and
  `autospec`) had unpredictable results, now it is an error
* BUGFIX: using `spec=True` *and* `create=True` as arguments to patchers could
  result in using `DEFAULT` as the spec. Now it is an error instead
* BUGFIX: using `spec` or `autospec` arguments to patchers, along with
  `spec_set=True` did not work correctly
* BUGFIX: using an object that evaluates to False as a spec could be ignored
* BUGFIX: a list as the `spec` argument to a patcher would always result in a
  non-callable mock. Now if `__call__` is in the spec the mock is callable

All the best,

Michael Foord


May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing 

More information about the testing-in-python mailing list