pypi / pytest-mock
pytest-mock
What changed in pytest-mock 2 to 3, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
6 breaking1 new APIs and options1 behavior and defaults16 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initpytest-mock 321 changes
Breaking changes 3
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.
Python 2.7 and 3.4 are no longer supported; users using pip 9 or later will install a compatible version automatically.
New APIs and options 1
Added SpyType for annotating mocker.spy results.
Behavior and default changes 1
mocker.spy now also works with async def functions.
Fixes and other changes 16
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.
pytest-mock 23 changes
Breaking changes 3
The deprecated mock alias to the mocker fixture has been removed.
Spied functions’ raised exceptions are now tracked through spy_exception instead of the MagicMock side_effect attribute.
Spied functions’ returned values are now tracked through spy_return instead of the MagicMock return_value attribute.