pypi / pytest-mock
pytest-mock
What changed in pytest-mock 3, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-18.
2 breaking1 new APIs and options17 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initpytest-mock 320 changes
Breaking changes 2
Handling for this RuntimeError was removed because it can no longer occur in supported Python versions.
Support for Python 3.9 was dropped because it is EOL.
New APIs and options 1
Added SpyType for annotating mocker.spy results.
Fixes and other changes 17
Failures no longer show pytest introspection comparing expected and actual calls position by position; the mock's own message listing both is retained.
Failures no longer show pytest introspection comparing expected and actual calls position by position; the mock's own message listing both is retained.
Mock assertion failures are reported only once, without chaining the original mock-module error before them.
Assertion failures no longer show misleading introspection for assertions unrelated to the last call's arguments; autospecced positional and keyword arguments are treated alike, and empty sections are omitted when rewriting is unavailable.
Failure introspection is no longer misleading, and passing calls by keyword no longer raises IndexError instead of AssertionError.
Expected calls supplied as plain tuples no longer cause ValueError or misleading introspection.
resetall no longer skips mocks patched with patch.multiple, whether created by it or passed explicitly.
Resetting a spy's side_effect resumes calling the spied code and clears any side_effect set on the spy.
resetall also resets spies' spy_return and spy_exception, and no longer overwrites those attributes on non-spy mocks.
Stopping a mock no longer sometimes stops the wrong mock, including mocks from create_autospec.
When the same object is used in several patches, stop undoes the most recent patch first.
The value is cleared after a spied synchronous or asynchronous function raises, matching spy_return.
Async mock assertion introspection now uses awaited arguments instead of the latest call's arguments.
return_value=True now applies to non-callable mocks, including those returned by create_autospec.
side_effect=True now applies to non-callable mocks, including those returned by create_autospec.
Fixed duplicate_iterators=True for async functions spied with mocker.spy.
Added support for Python 3.15.