derwiki-adroll / mock

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

Adding 'args' and 'kwargs' attribute to Mock #170

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I find myself often writing the following in my tests:

    m = Mock()
    m.foo("bar", baz="baz")

    args = m.foo.call_args[0]
    kwargs = m.foo.call_args[1]

    self.assertEqual(args, ("bar"))
    self.assertEqual(kwargs, {'baz': "baz"}

I thought it could be more readable if Mock had an 'args' and a 'kwargs' 
attributes with these values:

    self.assertEqual(m.foo.args, ("bar"))
    self.assertEqual(m.foo.kwargs, {'baz': "baz"})

There is a patch attached that does just that.

Original issue reported on code.google.com by Rodrigue...@gmail.com on 1 Sep 2012 at 8:23

Attachments:

GoogleCodeExporter commented 9 years ago
"args" and "kwargs" attributes on mocks could clash with user defined 
attributes on objects.

It looks like we'll be adding args and kwargs attributes to the call objects 
instead. See issue 164:

http://code.google.com/p/mock/issues/detail?id=164 

Original comment by fuzzyman on 3 Sep 2012 at 8:41