NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #299 most downloaded on PyPI
Thin-wrapper around the mock package for easier use with pytest
Last release 7 days ago
27 Sep 2026
Release timing varies
gaps range from 1 weeks to 1.2 years
Nearly every release is documented
notes for 59 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
67 releases · first in 2014
Dropped support for EOL Python 3.9.
2026-09-27
duplicate_iterators=True for async functions spied with mocker.spy.mocker.resetall(return_value=True, side_effect=True) now also applies to non-callable mocks, such as those returned by mocker.create_autospec(SomeClass, instance=True). Previously both arguments were silently ignored for them.SpyType for annotating mocker.spy results.RuntimeError: stop called on unstarted patcher, which can no longer occur in the supported Python versions.One column per quarter.
2025-09-16 #529 : Fixed itertools._tee object has no attribute error -- now duplicate_iterators=True must be passed to mocker.spy to duplicate iterato
2025-09-16
itertools._tee object has no attribute error -- now duplicate_iterators=True must be passed to mocker.spy to duplicate iterators.Python 3.8 (EOL) is no longer supported.
2025-09-04
spy_return_iter to mocker.spy, which contains a duplicate of the return value of the spied method if it is an Iterator.#503 : Python 3.14 is now officially supported.
#415 : MockType and AsyncMockType can be imported from pytest_mock for type annotation purposes. #420 : Fixed a regression which would cause mocker.pa
pytest-mock now requires pytest>=6.2.5 .
spy now has spy_return_list, which is a list containing all the values returned by the spied function.pytest-mock now requires pytest>=6.2.5.setup.py file is removed.setup.py install,Dropped support for EOL Python 3.7.
mocker.resetall() now also resets mocks created by mocker.create_autospec (#390).Fixed introspection for failed assert_has_calls ( #365 ).
(This release source code is identical to 3.11.0 except a small internal fix to deployment/CI)
Fixed introspection for failed assert_has_calls (#365_).
Added new mocker.stop(m) method to stop specific mocker.patch or mocker.spy calls ( #319 ).
mocker.stop(m) method to stop specific mocker.patch or mocker.spy calls (#319).Expose NonCallableMagicMock via the mocker fixture ( #318 ).
NonCallableMagicMock via the mocker fixture (#318).Fixed AsyncMock support for Python 3.7+ in mocker.async_stub (\#302).
AsyncMock support for Python 3.7+ in mocker.async_stub (#302).Fix regression caused by an explicit mock dependency in the code (\#298).
mock dependency in the code (#298).Fixed regression caused by an explicit mock dependency in the code (#298).
Add MockerFixture.async_mock method. Thanks \@PerchunPak for the PR (\#296).
MockerFixture.async_mock method. Thanks @PerchunPak for the PR (#296).Add MockerFixture.async_mock method. Thanks @PerchunPak for the PR (#296).
Python 3.10 now officially supported.
Fix mocker.resetall() when using mocker.spy() (\#237). Thanks \@blaxter for the report and \@shadycuz for the PR.
pytest-mock no longer supports Python 3.5.
mocker.patch.object to also include the string form.
Thanks @plannigan for the PR (#235).reset_all now supports return_value and side_effect keyword arguments. Thanks @alex-marty for the PR (#214).Use inspect.getattr_static instead of resorting to object.__getattribute__ magic. This should better comply with objects which implement a custom desc
inspect.getattr_static instead of resorting to object.__getattribute__
magic. This should better comply with objects which implement a custom descriptor
protocol. Thanks @yesthesoup for the PR (#224).Now all patch functions will emit a warning instead of raising a ValueError when used as a context-manager. Thanks \@iforapsy for the PR (\#221).
ValueError when used
as a context-manager. Thanks @iforapsy for the PR (#221).mocker.patch.context_manager is available when the user intends to mock
a context manager (for example threading.Lock object), which will not emit that
warning.Add [mock.seal]{.title-ref} alias to the [mocker]{.title-ref} fixture (\#211). Thanks \@coiax for the PR.
Add [mock.seal]{.title-ref} alias to the [mocker]{.title-ref} fixture (#211). Thanks @coiax for the PR.
Fixed spying on exceptions not covered by the Exception
superclass (#215), like KeyboardInterrupt -- PR #216
by @webknjaz.
Before the fix, both spy_return and spy_exception
were always assigned to None
whenever such an exception happened. And after this fix,
spy_exception is set to a correct value of an exception
Add mock.seal alias to the mocker fixture (#211). Thanks @coiax for the PR.
Fixed spying on exceptions not covered by the Exception superclass (#215), like KeyboardInterrupt -- PR #216 by @webknjaz.
Before the fix, both spy_return and spy_exception were always assigned to None whenever such an exception happened. And after this fix, spy_exception is set to a correct value of an exception that has actually happened.
Introduce MockFixture as an alias to MockerFixture.
Introduce MockFixture as an alias to MockerFixture.
Before 3.3.0, the fixture class was named MockFixture, but was renamed to MockerFixture to better
match the mocker fixture. While not officially part of the API, it was later discovered that this broke
the code of some users which already imported pytest_mock.MockFixture for type annotations, so we
decided to reintroduce the name as an alias.
Note however that this is just a stop gap measure, and new code should use MockerFixture for type annotations.
Improved typing for MockerFixture.patch (#201). Thanks @srittau for the PR.
pytest-mock now includes inline type annotations and exposes them to user programs. The mocker fixture returns pytest_mock.MockerFixture, which can be
pytest-mock now includes inline type annotations and exposes them to user programs. The mocker fixture returns pytest_mock.MockerFixture, which can be used to annotate your tests:
from pytest_mock import MockerFixture
def test_foo(mocker: MockerFixture) -> None:
...
The type annotations were developed against mypy version 0.782, the minimum version supported at the moment. If you run into an error that you believe to be incorrect, please open an issue.
Many thanks to @staticdev for providing the initial patch #199.
AsyncMock is now exposed in mocker and supports provides assertion introspection similar to Mock objects.
AsyncMock is now exposed in mocker and supports provides assertion introspection similar to Mock objects.
Added by @tirkarthi in #197.
Fixed performance regression caused by the ValueError raised when mocker is used as context manager (#191).
ValueError raised
when mocker is used as context manager (#191).New mocker fixtures added that allow using mocking functionality in other scopes:
Python 2.7 and 3.4 are no longer supported. Users using pip 9 or later will install a compatible version automatically.
mocker.spy now also works with async def functions (#179). Thanks @frankie567 for the PR!The deprecated mock alias to the mocker fixture has finally been removed.
mocker.spy attributes for tracking returned values and raised exceptions of its spied functions
are now called spy_return and spy_exception, instead of reusing the existing
MagicMock attributes return_value and side_effect.
Version 1.13 introduced a serious regression: after a spied function using mocker.spy
raises an exception, further calls to the spy will not call the spied function,
always raising the first exception instead: assigning to side_effect causes
unittest.mock to behave this way (#175).
The deprecated mock alias to the mocker fixture has finally been removed.
The object returned by mocker.spy now also tracks any side effect of the spied method/function.
mocker.spy now also tracks any side effect of the spied method/function.Fix error if mocker.patch is used in code where the source file is not available, for example stale .pyc files (#169).
mocker.patch is used in code where the source file is not available, for example stale .pyc files (#169).Now all patch functions also raise a ValueError when used as a context-manager. Thanks @AlexGascon for the PR (#168).
Now all patch functions also raise a ValueError when used as a context-manager. Thanks @AlexGascon for the PR (#168).
The *pytest introspection follows* message is no longer shown if there is no pytest introspection (#154). Thanks @The-Compiler for the report.
Fix mocker.spy on Python 2 when used on non-function objects which implement __call__ #157. Thanks @pbasista for the report.
mocker.spy now also tracks the return value.
mocker.spy now also tracks the return value.The object returned by mocker.spy now also tracks the return value of the spied method/function.
Fix plugin when 'terminal' plugin is disabled
Fix plugin when 'terminal' plugin is disabled
Fix test suite in Python 3.8. Thanks @hroncok_ for the report and @blueyed_ for the PR (#140_).
Fix bug at the end of the test session when a call to patch.stopall is done explicitly by user code. Thanks @craiga_ for the report (#137_).
Fix broken links and update README. Also the code is now formatted using black __.
Fix broken links and update README. Also the code is now formatted using black.
Add support for the recently added assert_called method in Python 3.6 and mock-2.0. Thanks @rouge8_ for the PR (#115_).
Add support for the recently added assert_called method in Python 3.6 and mock-2.0. Thanks `@rouge8`_ for the PR (#115).
Add support for the recently added assert_called_once method in Python 3.6 and mock-2.0. Thanks @rouge8_ for the PR (#113_).
Add support for the recently added assert_called_once method in Python 3.6 and mock-2.0. Thanks `@rouge8`_ for the PR (#113).
Add aliases for NonCallableMock and create_autospec to mocker. Thanks @mlhamel_ for the PR (#111_).
Add aliases for NonCallableMock and create_autospec to mocker. Thanks `@mlhamel`_ for the PR (#111).
Fix setup.py to correctly read the README.rst. Thanks @ghisvail_ for the fix (#107_).
Fix setup.py to correctly read the README.rst. Thanks `@ghisvail`_ for the fix (#107).
pytest-mock no longer supports Python 2.6 and Python 3.3, following the lead of pytest and other projects in the community. Thanks @hugovk_ for the PR
Fix UnicodeDecodeError during assert introspection in assert_called_with in Python 2. Thanks @AndreasHogstrom_ for the report (#91_).
Fix UnicodeDecodeError during assert introspection in assert_called_with in Python 2. Thanks @AndreasHogstrom for the report (#91).
Provide source package in tar.gz format and remove obsolete MANIFEST.in.
Provide source package in tar.gz format and remove obsolete MANIFEST.in.
Fix mocker.resetall() by ignoring mocker objects which don't have a resetall method, like for example patch.dict. Thanks @jdavisp3_ for the PR (#88_).
The original assertions raised by the various Mock.assert_* methods now appear in the failure message, in addition to the message obtained from pytest
The original assertions raised by the various Mock.assert_* methods now appear in the failure message, in addition to the message obtained from pytest introspection. Thanks @quodlibetor for the initial patch (#79).
New mocker.mock_module variable points to the underlying mock module being used (unittest.mock or mock). Thanks @blueyed_ for the request (#71_).
New mocker.mock_module variable points to the underlying mock module being used (unittest.mock or mock). Thanks `@blueyed`_ for the request (#71).
New configuration variable, mock_use_standalone_module (defaults to False). This forces the plugin to import mock instead of unittest.mock on Python 3
New configuration variable, mock_use_standalone_module (defaults to False). This forces the plugin to import mock instead of unittest.mock on Python 3. This is useful to import a newer version than the one available in the Python distribution.
Previously the plugin would first try to import mock and fallback to unittest.mock in case of an ImportError, but this behavior has been removed because it could hide hard to debug import errors (#68).
Now mock (Python 2) and unittest.mock (Python 3) are lazy-loaded to make it possible to implement the new mock_use_standlone_module configuration option. As a consequence of this the undocumented pytest_mock.mock_module variable, which pointed to the actual mock module being used by the plugin, has been removed.
DEFAULT is now available from the mocker fixture.
Add support for Python 3.6. Thanks @hackebrot_ for the report (#59_).
Add support for Python 3.6. Thanks @hackebrot for the report (#59).
mock.mock_open is now aliased as mocker.mock_open for convenience. Thanks @pokidovea for the PR (#66).
Try to import mock first instead of unittest.mock. This gives the user flexibility to install a newer mock version from PyPI instead of using the one
Try to import mock first instead of unittest.mock. This gives the user flexibility to install a newer mock version from PyPI instead of using the one available in the Python distribution. Thanks @wcooley for the PR (#54).
mock.sentinel is now aliased as mocker.sentinel for convenience. Thanks @kjwilcox for the PR (#56).
From this version onward, pytest-mock is licensed under the MIT_ license (#45_).
From this version onward, pytest-mock is licensed under the MIT license (#45).
Now the plugin also adds introspection information on differing call arguments when calling helper methods such as assert_called_once_with. The extra introspection information is similar to pytest's and can be disabled with the mock_traceback_monkeypatch option. Thanks @asfaltboy for the PR (#36).
mocker.stub() now allows passing in the name for the constructed Mock object instead of having to set it using the internal _mock_name attribute directly. This is useful for debugging as the name is used in the mock's repr string as well as related assertion failure messages. Thanks @jurko-gospodnetic for the PR (#40).
Monkey patching mock module for friendlier tracebacks is automatically disabled with the --tb=native option. The underlying mechanism used to suppress traceback entries from mock module does not work with that option anyway plus it generates confusing messages on Python 3.5 due to exception chaining (#44). Thanks `@blueyed`_ for the report.
mock.call is now aliased as mocker.call for convenience. Thanks @jhermann for the PR (#49).
Fix AttributeError with mocker.spy when spying on inherited methods (#42_). Thanks @blueyed_ for the PR.
PropertyMock _ is now accessible from mocker. Thanks @satyrius_ for the PR (#32_).
PropertyMock is now accessible from mocker. Thanks @satyrius for the PR (#32).
Fix regression using one of the assert_* methods in patched functions which receive a parameter named method. Thanks @sagarchalise for the report (#31).
Fix regression in frozen tests due to distutils import dependency. Thanks @The-Compiler_ for the report (#29_).
Nothing published for this version
New mocker.resetall function, which calls reset_mock() in all mocked objects up to that point. Thanks to @mathrick_ for the PR!
New mocker.resetall function, which calls reset_mock() in all mocked objects up to that point. Thanks to `@mathrick`_ for the PR!
mock.ANY is now accessible from the mocker fixture (#17), thanks @tigarmo for the PR!
mock.ANY is now accessible from the mocker fixture (#17), thanks @tigarmo for the PR!pytest-mock is now also available as a wheel. Thanks @rouge8 for the PR!Thanks to @fogo, mocker.spy can now prey upon staticmethods and classmethods. :smile:
Thanks to @fogo, mocker.spy can now prey upon staticmethods and classmethods. :smile:
Two new auxiliary methods, spy and stub. See README for usage. (Thanks @fogo for complete PR!)
Two new auxiliary methods, spy and stub. See README for usage. (Thanks @fogo for complete PR!)
Mock and MagicMock are now accessible from the mocker fixture, many thanks to @marcwebbie for the complete PR!
Mock and MagicMock are now accessible from the mocker fixture, many thanks to @marcwebbie for the complete PR!
Your coding agent can read these notes before it upgrades. Set up the MCP server →