Skip to content

0.2.0

Choose a tag to compare

@claudiubelu claudiubelu released this 17 Jul 13:56
· 6 commits to main since this release

Fixes

  • -> Any return annotations no longer break attribute access. isinstance(typing.Any, type) is True on Python 3.11+, so mockey was autospeccing return values against typing.Any itself, whose empty attribute list rejected any attribute access on the mocked return value.

  • spec=/spec_set= as a list of names no longer mutates the caller's list. mockey appended its own bookkeeping name (_mock_check_sig) directly into the list object the caller passed, since stdlib stores list specs by reference. The list is now copied first.

  • Explicit return_value= is no longer clobbered by return-type autospec. If a caller passed mock.patch(..., return_value=X), mockey was overwriting it based on the patched callable's -> ReturnType annotation, silently discarding correctly-typed values, and for falsy values like return_value=False on a -> bool callable, potentially flipping which branch code under test took.

  • Mock(autospec=callable) now enforces the call signature for any callable, not just classes. Functions, bound methods, classmethods, and staticmethods previously went through unchecked.

  • Mock(autospec=X) now satisfies isinstance(obj, X), matching mock.create_autospec(X, instance=True) behaviour, while keeping mockey's lazy signature checking.

  • Removed a broken "already-mocked-target" autospec guard. Re-patching an already-mocked target with autospec is a test anti-pattern that should raise InvalidSpecError per upstream's own stance (bpo-43478), not silently succeed with a lost spec. The old guard was also broken for MagicMock-lineage targets.

  • Descriptor protocol methods (__get__, __set__, __delete__, __set_name__) no longer have eat_self incorrectly applied. Python's descriptor machinery invokes these directly as (self, instance, owner), not through normal method binding.

  • functools.partial patch targets now get signature enforcement. Previously create_autospec fell back to a generic MagicMock with no call-signature checking, even with autospec=True explicitly passed.

  • functools.partialmethod now gets correct eat_self handling instead of being enforced with the wrong signature.

  • mock.patch used as a decorator on a shared helper no longer leaks autospec state across calls. The same _patch instance is reused on every invocation; mockey was permanently clobbering self.autospec on first __enter__, causing later calls with an explicit autospec=False to be treated as mockey's default (True), breaking targets whose __dir__ raises (e.g. pecan.request).

Docs

  • README now documents Mock / MagicMock autospec= support, mock.patch autospec-by-default behavior, and return-type autospeccing; longer-form content (oslotest diff, performance, known limitations) moved into docs/ to keep the README scannable.

Full Changelog: 0.1.0...0.2.0