mock.ANY
Thursday, 10 June 2021
Asserting successive calls to a mock method
>>> from unittest.mock import call, Mock
>>> mock = Mock(return_value=None)
>>> mock(1)
>>> mock(2)
>>> mock(3)
>>> mock(4)
>>> calls = [call(2), call(3)]
>>> mock.assert_has_calls(calls)
>>> calls = [call(4), call(2), call(3)]
>>> mock.assert_has_calls(calls, any_order=True)
from: https://stackoverflow.com/questions/7242433/asserting-successive-calls-to-a-mock-method
Wednesday, 2 June 2021
Set nested dict value and create intermediate keys
from collections import defaultdict
recursivedict = lambda: defaultdict(recursivedict)
mydict = recursivedict()
from: https://stackoverflow.com/questions/10218486/set-nested-dict-value-and-create-intermediate-keys
Subscribe to:
Posts (Atom)