Repository navigation
Releases: pytest-dev/pytest-mock
Releases · pytest-dev/pytest-mock
Release list
v3.17.0
2026-10-17
- #641: Failures of mock assertions such as
assert_called_withare again reported only once, instead of two or three times with the original error from themockmodule chained before them. - #642: Mock assertion failures no longer show misleading introspection when they are not about the arguments of the last call:
assert_called,assert_called_once,assert_not_called,assert_any_call, theirawaitcounterparts, andassert_called_once_with/assert_awaited_once_withwhen the mock was not called (awaited) exactly once. The introspection also no longer reports arguments passed by position versus by keyword as different for autospecced mocks, and no longer shows emptyArgs:/Kwargs:sections when assertion rewriting is not available. - #643:
assert_has_callsandassert_has_awaitsfailures no longer show pytest introspection, which compared the expected and actual calls position by position and so reported differences between unrelated calls. The mock's own message, listing the expected and actual calls, is still shown.
v3.16.1
2026-10-17
- #617: Fixed
assert_has_callsraisingValueErrorinstead ofAssertionError(or showing misleading introspection) when the expected calls are plain tuples rather thancall(...)objects, such as(args, kwargs)entries of another mock'scall_args_list,(args,),(kwargs,),(name, args)or(name, kwargs). - #621: Fixed
mocker.stop()sometimes stopping the wrong mock, for example with mocks frommocker.create_autospec. - #621:
mocker.stop()now undoes the most recent patch first when the same object is used in several patches. - #623: Fixed misleading introspection in
assert_has_awaitsfailures, andassert_has_calls/assert_has_awaitsraisingIndexErrorinstead ofAssertionErrorwhencallsis passed by keyword. - #624: Clear
spy_return_iterafter a spied synchronous or asynchronous function raises, matchingspy_return. - #627: Document
async_stubawait assertions and the distinction between call and await tracking. - #629: Fixed
mocker.resetall()skipping the mocks patched withmocker.patch.multiple(), both the ones it creates and the ones passed explicitly. - #630:
mocker.resetall()now also resetsspy_returnandspy_exceptionof spies, like it already did forspy_return_listandspy_return_iter, and no longer overwrites attributes with these names on mocks that are not spies. - #633: Fixed spies on
classmethod,staticmethod, builtins and classes returning aMagicMockinstead of calling the spied code aftermocker.resetall(side_effect=True). Resetting a spy'sside_effectnow goes back to calling the spied code, also clearing anyside_effectset on the spy.
v3.16.0
2026-09-27
- #604: Fixed
duplicate_iterators=Truefor async functions spied withmocker.spy. - #611: Fixed async mock assertion introspection to use awaited arguments instead of the latest call's arguments.
- #606:
mocker.resetall(return_value=True, side_effect=True)now also applies to non-callable mocks, such as those returned bymocker.create_autospec(SomeClass, instance=True). Previously both arguments were silently ignored for them. - #547: Added
SpyTypefor annotatingmocker.spyresults. - Dropped support for EOL Python 3.9.
- #147: Removed handling of
RuntimeError: stop called on unstarted patcher, which can no longer occur in the supported Python versions. - Added support for Python 3.15.
v3.15.1
2025-09-16
- #529: Fixed
itertools._tee object has no attribute error-- nowduplicate_iterators=Truemust be passed tomocker.spyto duplicate iterators.
v3.15.0
2025-09-04
- Python 3.8 (EOL) is no longer supported.
- #524: Added
spy_return_itertomocker.spy, which contains a duplicate of the return value of the spied method if it is anIterator.
v3.14.1
- #503: Python 3.14 is now officially supported.
v3.14.0
v3.13.0
- #417:
spynow hasspy_return_list, which is a list containing all the values returned by the spied function. pytest-mocknow requirespytest>=6.2.5.- #410: pytest-mock's
setup.pyfile is removed.
If you relied on this file, e.g. to install pytest usingsetup.py install,
please see Why you shouldn't invoke setup.py directly for alternatives.
v3.12.0
- Added support for Python 3.12.
- Dropped support for EOL Python 3.7.
mocker.resetall()now also resets mocks created bymocker.create_autospec(#390).