Conversation
Treat __aenter__, __aexit__, and __anext__ as awaitable protocol methods for unspecced mock() objects when configured via when(...).thenReturn/thenRaise/thenAnswer flows. Centralize awaitable detection in Mock.method_expects_awaitable(). Reuse it for method replacement coroutine marking, and update StubbedInvocation to use the shared logic. Add focused regression tests in tests/async_protocol_methods_test.py, including functional async with and async for scenarios, plus awaitable checks for __aenter__/__aexit__ and __anext__.
Include AtMost in verification_has_lower_bound_of_zero() so explicit zero-match verification with atmost=n marks matching stubs as intentionally checked. This aligns bookkeeping with existing verification semantics where atmost already allows zero matches, and fixes follow-up verifyStubbedInvocationsAreUsed/InOrder zero-lower-bound flows.
Add focused tests showing that typing.Protocol works as a spec for method existence checks, async/sync method behavior, and signature validation, including inherited override signatures.
Create internal chain mocks in strict mode so unexpected/unconfigured chain segments fail early with InvocationError instead of returning None and crashing later with AttributeError. Add regression coverage in chaining_test.py that asserts the exact error message for mismatched chain segment arguments.
Partially reverts 8f13528 ("Fix dummy single-stub rollback with registry unstub_mock") In the test for the patch, we can clearly see that `dog` is still in the scope of the function, so we cannot unregister it which would break its tie its theMock. In fact expecting `ArgumentError` is wrong for the non-strict mock. For `verify` we raise a `VerificationError`, and ensure that by testing before and after the failing configuration try.
e8b67cb to
4446697
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some fixes but also rollback the "specifiticity" feature. Last-one-wins is easy enough to explain, and esp. has no surprises when you configure first in
setUpand then want to to tune that in a test file. Here clearly the later config should win.