Skip to content

0.3.0

Latest

Choose a tag to compare

@claudiubelu claudiubelu released this 02 Aug 13:39
5a39769

Added

  • mock.AsyncMock(autospec=X) now gets the same autospec support as Mock / MagicMock. Previously autospec was treated as an arbitrary config kwarg on AsyncMock (silently becoming a child mock named .autospec), so async classes /methods got no autospec support at all.
  • An explicit spec=[...] / spec_set=[...] list alongside autospec= is now handled as a whitelist instead of being replaced. This makes it possible to allow instance attributes only ever assigned in __init__ (invisible to autospec's dir()-based discovery) alongside autospec's own signature checking. This is something with no clean upstream equivalent once spec_set=True is in effect.

Fixes

  • Async mock.patch targets now enforce call signatures correctly, with no spurious warnings. An async def patch target makes create_autospec return an AsyncMock, whose signature check only runs inside the awaited coroutine body; the fixture's synchronous check was discarding it, so on Python 3.13+ enforcement was silently dropped entirely.
  • Patching a builtin on a module (open, print, ...) no longer raises AttributeError under the default autospec=True. Autospecs are now skipped for builtins, mirroring stdlib's behaviour. Autospeccing builtins offers little benefit as there are only a few cases in which that is needed; the most common case would be open, but mock.mock_open() can be used for that instead.
  • Autospec now propagates recursively into nested non-callable attributes. A class-level attribute that was itself a spec-able object (e.g. Outer.inner = Inner()) previously got a plain, unspecced child mock, so calls like mock.Mock(autospec=Outer)().inner.method(...) went completely unchecked.

Docs

  • README now documents mock.AsyncMock autospec support and the spec= / spec_set= whitelist pattern, with runnable examples.
  • Removed a stale known-limitation entry ("patching a builtin on a module raises AttributeError") that no longer applies.

Full Changelog: 0.2.0...0.3.0