Skip to content

Releases: pytest-dev/pytest-mock

v3.17.0

Choose a tag to compare

@github-actions github-actions released this 17 Oct 16:22

2026-10-17

  • #641: Failures of mock assertions such as assert_called_with are again reported only once, instead of two or three times with the original error from the mock module 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, their await counterparts, and assert_called_once_with/assert_awaited_once_with when 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 empty Args:/Kwargs: sections when assertion rewriting is not available.
  • #643: assert_has_calls and assert_has_awaits failures 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

Choose a tag to compare

@github-actions github-actions released this 17 Oct 15:21

2026-10-17

  • #617: Fixed assert_has_calls raising ValueError instead of AssertionError (or showing misleading introspection) when the expected calls are plain tuples rather than call(...) objects, such as (args, kwargs) entries of another mock's call_args_list, (args,), (kwargs,), (name, args) or (name, kwargs).
  • #621: Fixed mocker.stop() sometimes stopping the wrong mock, for example with mocks from mocker.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_awaits failures, and assert_has_calls/assert_has_awaits raising IndexError instead of AssertionError when calls is passed by keyword.
  • #624: Clear spy_return_iter after a spied synchronous or asynchronous function raises, matching spy_return.
  • #627: Document async_stub await assertions and the distinction between call and await tracking.
  • #629: Fixed mocker.resetall() skipping the mocks patched with mocker.patch.multiple(), both the ones it creates and the ones passed explicitly.
  • #630: mocker.resetall() now also resets spy_return and spy_exception of spies, like it already did for spy_return_list and spy_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 a MagicMock instead of calling the spied code after mocker.resetall(side_effect=True). Resetting a spy's side_effect now goes back to calling the spied code, also clearing any side_effect set on the spy.

v3.16.0

Choose a tag to compare

@github-actions github-actions released this 27 Sep 14:58

2026-09-27

  • #604: Fixed duplicate_iterators=True for async functions spied with mocker.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 by mocker.create_autospec(SomeClass, instance=True). Previously both arguments were silently ignored for them.
  • #547: Added SpyType for annotating mocker.spy results.
  • 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

Choose a tag to compare

@github-actions github-actions released this 16 Sep 16:40
e1b5c62

2025-09-16

  • #529: Fixed itertools._tee object has no attribute error -- now duplicate_iterators=True must be passed to mocker.spy to duplicate iterators.

v3.15.0

Choose a tag to compare

@github-actions github-actions released this 04 Sep 20:59

2025-09-04

  • Python 3.8 (EOL) is no longer supported.
  • #524: Added spy_return_iter to mocker.spy, which contains a duplicate of the return value of the spied method if it is an Iterator.

v3.14.1

Choose a tag to compare

@github-actions github-actions released this 26 May 13:58
34dd61a
  • #503: Python 3.14 is now officially supported.

v3.14.0

Choose a tag to compare

@github-actions github-actions released this 21 Mar 22:14
  • #415: MockType and AsyncMockType can be imported from pytest_mock for type annotation purposes.
  • #420: Fixed a regression which would cause mocker.patch.object to not being properly cleared between tests.

v3.13.0

Choose a tag to compare

@github-actions github-actions released this 21 Mar 19:07
  • #417: 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.
  • #410: pytest-mock's setup.py file is removed.
    If you relied on this file, e.g. to install pytest using setup.py install,
    please see Why you shouldn't invoke setup.py directly for alternatives.

v3.12.0

Choose a tag to compare

@github-actions github-actions released this 19 Oct 16:26
  • Added support for Python 3.12.
  • Dropped support for EOL Python 3.7.
  • mocker.resetall() now also resets mocks created by mocker.create_autospec (#390).

v3.11.1

Choose a tag to compare

@github-actions github-actions released this 15 Jun 23:58
  • Fixed introspection for failed assert_has_calls (#365).

  • Updated type annotations for mocker.patch and mocker.spy (#364).