python - Why does Order matter in Kwarg parameters in MagicMock asserts? -


i have test mocking filter call on manager. assert looks this:

filter_mock.assert_called_once_with(type_id__in=[3, 4, 5, 6], finance=mock_finance, parent_transaction__date_posted=tran_date_posted) 

and code being tested looks this:

agregates = balance.objects.filter(             finance=self.finance,type_id__in=self.balance_types,             parent_transaction__date_posted__lte=self.transaction_date_posted         ) 

i thought since these kwargs, order shouldn't matter, test failing, though values each pair match. below error seeing:

assertionerror: expected call: filter(type_id__in=[3, 4, 5, 6], parent_transaction__date_posted=datetime.datetime(2015, 5, 29, 16, 22, 59, 532772), finance=) actual call: filter(type_id__in=[3, 4, 5, 6], finance=, parent_transaction__date_posted__lte=datetime.datetime(2015, 5, 29, 16, 22, 59, 532772))

what heck going on? kwarg order should not matter, , if order match test asserting, test still fails.

your keys not same. in assert_called_with, have key parent_transaction__date_posted, in code using key parent_transaction__date_posted__lte. causing test fail, not bad sorting. here own test proof of concept:

    >>> myobject.test(a=1, b=2)     >>> mock_test.assert_called_with(b=2, a=1)     ok     >>> myobject.test(a=1, b__lte=2)     >>> mock_test.assert_called_with(b=2, a=1)     assertionerror: expected call: test(a=1, b=2)     actual call: test(a=1, b__lte=2) 

you need correct either test or code match (include __lte or don't depending on need)


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -