Mockito

Latest version: v1.5.3

Safety actively analyzes 681881 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 3 of 5

1.0.12

-----------------------------

- Better error messages for failed verifications. By lwoydziak

1.0.7

------------------------------------------------------

- ``verifyZeroInteractions`` implemented. This is actually a *breaking change*, because ``verifyZeroInteractions`` was an alias for ``verifyNoMoreInteractions`` (sic!). If you used it, just call the other function.

- ``verifyStubbedInvocationsAreUsed`` implemented. This is meant to be called right before an ``unstub`` and should improve long time maintenance. It doesn't help during design time. Note that `pytest-mockito` automatically calls this for you.

- All `verify*` functions now warn you if you pass in an object which was never stubbed.

1.0.0

---------------------------------------------

This is a major update; mostly because of internal code reorganization (`imports`) it cannot be guaranteed that this will not break for you. Though if you just used the public API you should be fine. None of the vintage old tests have been removed and they at least pass.

In general unclassified imports (``from mocktio import *``) are not recommended. But if you did, we do not export `Mock` anymore. `Mock` has been deprecated long ago and is now for internal use only. You must use `mock`.

Another important change is, that *mockito*'s strict mode is far more strict than before. We now generally try to match the signature of the target method
with your usage. Usually this should help you find bugs in your code, because
it will make it easier to spot changing interfaces.

- ``mock``, ``when``, ``verify`` return mostly empty objects. It is unlikely to have a method_name clash.

- Specced mocks ``instance = mock(Class)`` will pass isinstance tests like ``isinstance(instance, Class)``

- For ``when`` and ``verify`` the function signature or argument matchers can be greatly simplified. E.g. ``when(requests).get(...).thenReturn('OK')`` will match any argument you pass in. There are ``args`` and ``kwargs`` matchers as well. So ``when(requests).get('https://...', **kwargs).thenReturn(...)`` will make an exact match on the first argument, the url, and ignore all the headers and other stuff.

- Mocks can be preconfigured: ``mock({'text': 'OK'})``. For specced mocks this would be e.g. ``mock({'text': 'OK'}, spec=requests.Response)``.

- If you mock or patch an object, the function signatures will be matched. So::

def foo(a, b=1): ...

when(main).foo(12) will pass
when(main).foo(c=13) will raise immediately

- Mock Dummies are now callable::

m = mock()
m(1, 2)
verify(m).__call__(...)

- ``Mock()`` is now an implementation detail; it is **not** exported anymore. Use ``mock()``.

- You can unstub individual patched objects ``unstub(obj)``. (Before it was all or nothing.)

- Added basic context manager support when using ``when``. Note that ``verify`` has to be called within the with context.

::

with when(rex).waggle().thenReturn('Yup'):
assert rex.waggle() == 'Yup'
verify(rex).waggle()

- Aliased ``any_`` to ``ANY``, ``args`` to ``ARGS`` and ``kwargs`` to ``KWARGS``. You can use python's builtin ``any`` as a stand in for ``ANY``.

- As a convenience you can use our ``any_`` matcher like a type instead of ``any_()``::

dummy(1)
verify(dummy).__call__(ANY)

- Added ``when2``, ``expect``, ``spy2``

- Make the mocked function (replacement) more inspectable. Copy `__doc__`, `__name__` etc.

- You can configure magic methods on mocks::

dummy = mock()
when(dummy).__getitem__(1).thenReturn(2)
assert dummy[1] == 2

0.7.1

---------------------------------

- Fix: Allow ``verifyNoMoreInteractions`` call for real (stubbed) objects

0.7.0

-----------------------------

- Added a ton of new argument matchers. Namely::

'and_', 'or_', 'not_', 'eq', 'neq', 'lt', 'lte', 'gt', 'gte',
'arg_that', 'matches', 'captor'

- Aliases ``any`` matcher to ``any_`` because it's a builtin.
- Fixes an issue where mockito could not correctly verify your function invocations, if you grabbed a method from its object and used it ('detached') as a plain function::

m = mock()
f = m.foo detach
f(1, 2) pass it around and use it like a function
f(2, 3)
verify(m).foo(...) finally verify interactions

Thank you maximkulkin

0.6.1

----------------------------

- Added ``thenAnswer(callable)``. The callable will be called to compute the answer the stubbed method will return. For that it will receive the arguments of the caller::

m = mock()
when(m).do_times(any(), any()).thenAnswer(lambda one, two: one * two)
self.assertEquals(20, m.do_times(5, 4))

Thank you stubbsd

Page 3 of 5

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.