fork download
  1. from unittest import mock, TestCase, TextTestRunner, TestLoader
  2.  
  3. class CallDiffingMock(mock.Mock):
  4. def assert_called_with(self, *args, **kwargs):
  5. self.assert_called()
  6. test = TestCase()
  7. test.assertTupleEqual(args, self.call_args.args)
  8. test.assertDictEqual(kwargs, self.call_args.kwargs)
  9.  
  10. class Test(TestCase):
  11. def test_call(self):
  12. f = CallDiffingMock()
  13. f(a=1, b=2)
  14. f.assert_called_with(a=1, b=2, c=3)
  15.  
  16. TextTestRunner().run(TestLoader().loadTestsFromTestCase(Test))
Success #stdin #stdout #stderr 0.08s 16396KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
F
======================================================================
FAIL: test_call (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./prog.py", line 14, in test_call
  File "./prog.py", line 8, in assert_called_with
AssertionError: {'a': 1, 'b': 2, 'c': 3} != {'a': 1, 'b': 2}
- {'a': 1, 'b': 2, 'c': 3}
?                --------

+ {'a': 1, 'b': 2}

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)