-
-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Good day
In version 2 it seems all context managers now verify whether when() clauses were used:
@pytest.fixture(autouse=True)
def mock_external():
with when(some_lib).request(...).thenReturn('mock value'):
yieldNow results in mockito.verification.VerificationError (unused stub)
While the docs do briefly cover this with the between=(0,) part, it is highly confusing - I didn't use any verification function here specifically because tests may or may not encounter this stub.
Please assist with clarity here? Are the verification functions only needed if you don't use context managers?
Maybe opinionated, but the current docs for e.g. expect seem to encourage a fragile paradigm. Why not promote context managers?
Existing docs:
# Given `dog` is an instance of a `Dog`
expect(dog, times=1).bark('Wuff').thenReturn('Miau')
dog.bark('Wuff')
dog.bark('Wuff') # will throw at call time: too many invocations
# maybe if you need to ensure that `dog.bark()` was called at all
verifyExpectedInteractions()becomes
with expect(dog, times=1).bark('Wuff').thenReturn('Miau'):
dog.bark('Wuff')
dog.bark('Wuff') # will throw at call time: too many invocations
# OR
expect(dog, times=1).bark('Wuff').thenReturn('Miau')
dog.bark('Wuff')
dog.bark('Wuff') # will throw at call time: too many invocations
# When not using the context manager, you will likely want to verify it was called at all:
verifyExpectedInteractions()Apologies if I missed the crucial part explaining this difference, I skim read the docs again after the update but didn't see it.
I would definitely think the "context manager vs not" paradigms should be explained (esp. regarding which verifications are automatic)
Thank you for the wonderful library!