@@ -4,73 +4,79 @@ MOCKITO CHANGE LOG
44
55Release 2.0.0 (March 10, 2026)
66------------------------------
7- - Packaging is now fully defined via ``pyproject.toml`` (``hatchling`` backend);
8- the obsolete ``setup.py`` shim has been removed.
9-
10- - Calling `thenAnswer()` without arguments is now allowed and is treated like
11- `thenReturn()` without arguments: the stubbed method will return `None`.
12-
137- Deprecate `verifyNoMoreInteractions` in favor of `ensureNoUnverifiedInteractions`.
148
159- Deprecate `verifyNoUnwantedInteractions` in favor of `verifyExpectedInteractions`.
1610
1711- Context managers now check usage and any expectations (set via `expect`) on exit. The usage
18- check can be disabled with the environment variable `MOCKITO_CONTEXT_MANAGERS_CHECK_USAGE="0"`.
12+ check can be disabled with the environment variable `` MOCKITO_CONTEXT_MANAGERS_CHECK_USAGE="0"` `.
1913
2014- The `between` matcher now supports open ranges, e.g. `between=(0,)` to assert that at least
2115 0 interactions occurred.
2216
23- - Added a first-class `InOrder` API via ``mockito.InOrder`` (also available as
24- ``mockito.inorder.InOrder``). The legacy in-order mode only supported one mock at a time;
17+ - Calling `thenAnswer()` without arguments is now allowed and is treated like
18+ `thenReturn()` without arguments: the stubbed method will return `None`.
19+
20+ - Added a first-class `InOrder` API via ``mockito.InOrder``.
21+ The legacy in-order mode only supported one mock at a time;
2522 the new API supports true cross-mock order verification.
2623
27- Migration (old limited style -> new style) ::
24+ Migration::
2825
29- # Before (legacy, single-mock order only)
26+ # Before
3027 from mockito import inorder
3128 inorder.verify(cat).meow()
3229 inorder.verify(cat).purr()
3330
34- # Now (preferred, explicit cross-mock order)
31+ # Now
3532 from mockito import InOrder
36- in_order = InOrder(cat, dog)
33+ in_order = InOrder(cat) # <== pass multiple objects for cross-mock verification!
3734 in_order.verify(cat).meow()
38- in_order .verify(dog).bark ()
35+ inorder .verify(cat).purr ()
3936
4037- The legacy in-order verification mode (``inorder.verify(...)``)
4138 is deprecated in favor of ``InOrder(...)``.
4239
4340- Added first-class async/await stubbing support: async callables now preserve
44- awaitable behavior for `thenReturn`, `thenRaise`, and `thenAnswer` (including
45- sync and async answer callables), with parity across `when`, `when2`,
46- `patch`, and `expect`.
47- Note that async introspection metadata (e.g. `inspect.iscoroutinefunction`)
48- for stub wrappers is currently implemented only on Python 3.12+.
49-
50- - Expanded `mock({...})` constructor shorthands:
51- - `"async <name>"` marks methods as async and supports either `...` or a function value.
52- - `{"__enter__": ...}` / `{"__aenter__": ...}` now install default matching
53- `__exit__` / `__aexit__` handlers when not provided.
54- - `{"__iter__": [..]}` and `{"__aiter__": [..]}` now normalize values into
55- proper iterator / async-iterator behavior.
56- - In constructor dict shorthands, zero-argument functions now widen to
57- accept arbitrary call arguments (e.g. `lambda: "ok"` behaves like
58- `lambda *a, **kw: "ok"`).
59-
60- - Added first-class property/descriptor stubbing support, including class-level property
61- stubbing via `when(F).p.thenReturn(...)` and `thenCallOriginalImplementation()` support for
62- property stubs (including chained answers like
63- `thenReturn(...).thenCallOriginalImplementation()`). Stubbing instance properties now fails
64- fast with clear guidance to use class-level stubbing (`when(F).p...`).
65-
66- - Added chained stubbing and expectations across call/property hops, e.g.
67- `when(cat).meow().purr().thenReturn(...)`, `when(User).query.filter_by(...).first()`, and
68- `expect(cat, times=1).meow().purr()`, including cleanup that preserves sibling chain branches.
69-
70- - Allow `...` in fixed argument positions as an ad-hoc `any` matcher.
71- Trailing positional `...` keeps its existing "rest" semantics.
72-
73- - Extend `captor` to be used as a rest matcher
41+ awaitable behavior for `thenReturn`, `thenRaise`, and `thenAnswer`.
42+
43+ .. note::
44+
45+ Async introspection metadata (e.g. ``inspect.iscoroutinefunction``)
46+ for stub wrappers is currently implemented only on Python 3.12+.
47+
48+ - Expanded ``mock({...})`` constructor shorthands; see :doc:`mock-shorthands`.
49+
50+ - Added first-class property/descriptor stubbing support.
51+
52+ E.g.::
53+
54+ class F:
55+ @property
56+ def p(self):
57+ return "orig"
58+
59+ when(F).p.thenReturn("stub")
60+ assert F().p == "stub"
61+
62+ - Added chained stubbing and expectations across call/property hops, e.g.::
63+
64+ when(cat).meow().purr().thenReturn(...)
65+ when(User).query.filter_by(...).first()
66+ expect(cat, times=1).meow().purr()
67+
68+ - Allow ``...`` in fixed argument positions as an ad-hoc `any` matcher.
69+ Trailing positional ``...`` keeps its existing "rest" semantics.
70+
71+ E.g.::
72+
73+ when(api).call("users", active=...).thenReturn("ok")
74+ assert api.call("users", active=True) == "ok"
75+ api.call("users") # will raise InvocationError, kwarg "active" is missing
76+
77+ when(api).call("users", ...) # used as a rest matcher as before
78+
79+ - Extend ``captor`` to be used as a rest matcher
7480
7581 E.g., support::
7682
@@ -89,7 +95,7 @@ Release 2.0.0 (March 10, 2026)
8995 mock.do(1, 2, x=3)
9096 assert call.value == ((1, 2), {"x": 3})
9197
92- - Added `patch_attr` and `patch_dict` for non-callable monkeypatch-style use cases
98+ - Added `` patch_attr`` and `` patch_dict` ` for non-callable monkeypatch-style use cases
9399 (e.g. `sys.stdout`, `sys.argv`, and environment/config dictionaries) with
94100 context-manager support and restoration through `unstub`.
95101
@@ -100,7 +106,7 @@ Release 2.0.0 (March 10, 2026)
100106 with patch_dict(os.environ, {"user": "bob"}): ...
101107
102108- Added explicit partial-`unstub` targeting by host + attribute name.
103- This complements method-reference partial unstub (e.g. `unstub(cat.meow)`)
109+ This complements method-reference partial unstub (e.g. `` unstub(cat.meow)` `)
104110 and supports tuple form and shorthand form, including multiple attributes
105111 in one call.
106112
@@ -111,7 +117,10 @@ Release 2.0.0 (March 10, 2026)
111117 unstub(cat, "meow")
112118 unstub((cat, "meow"), (os.path, "exists"))
113119
114- - Also implemented `unstub("os.path")`
120+ - Also implemented `unstub("os.path")` - the string variant.
121+
122+ - Packaging is now fully defined via ``pyproject.toml`` (``hatchling`` backend);
123+ the obsolete ``setup.py`` shim has been removed.
115124
116125
117126
0 commit comments