derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Provide more meaningful assertion messages for assert_called_with and assert_called_once_with #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. calling mock_instance.assert_called_with and assert_called_once_with
currently does show a error which is mostly misleading.

What is the expected output? What do you see instead?
The assertion errors should try to show the callee, as well as arguments if 
suitable.

So I cloned the mercurial repo, added more tests for the output I'm proposing, 
and the attached patch is already working.

Original issue reported on code.google.com by gabrielt...@gmail.com on 23 May 2011 at 8:27

Attachments:

GoogleCodeExporter commented 9 years ago
I really like the idea of making the failure messages for assert_called_with 
(etc) more understandable. 

How about an output like this:

   Expected to be called with: ('foo', 'bar', a=3, b=5)
   Actually called with: ('foo', 'bar', a=6, b=7)

(So showing the args as they would appear in the call?)

Because dictionary iteration order is arbitrary the keyword arguments may not 
always be in the same order, and objects with a long repr will make the output 
less useful, but it would still be a lot more understandable.

Original comment by fuzzyman on 28 May 2011 at 10:54

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 28 May 2011 at 10:54

GoogleCodeExporter commented 9 years ago
I agree 100%, would be even better. Can I do that and attach a new patch ?

Original comment by gabrielt...@gmail.com on 30 May 2011 at 2:45

GoogleCodeExporter commented 9 years ago
Sure, go ahead.

Original comment by fuzzyman on 30 May 2011 at 9:34

GoogleCodeExporter commented 9 years ago
I've improved the failure messages for assert_called_with and 
assert_called_once_with on head.

Original comment by fuzzyman on 17 Jul 2011 at 1:02