[TIP] Which mock object framework should I use?

Gustavo Niemeyer gustavo at niemeyer.net
Sun Nov 18 08:06:21 PST 2007

Hello Tarjei,

> Since you are working on a new Mock implementation, my wishlist is
> that you look at the api that is used by the simpletest package
> (simpletest.org) for mocking.

Will check it out, thanks for the pointer.

> What I like about the simpletest api is that it doesn't require too
> much typing.

I believe Mocker is quite friendly in that regard.

> Instead of : (example from pmock)

Btw, I started Mocker after Graham Carlyle (pmock's author) told me
he had dropped pmock when I offered him a patch.

> obj.expects(mock.once()).some_method(mock.eq('myparam'),mock.eq('otherparam')).will(mock.return_value('tt'))
> you can have:
> obj.expectOnce('some_method', ('myparam','otherparam'), 'tt')

That's how Mocker would handle it:

  expect(obj.some_method('my param', 'otherparam')).result('tt')


  obj.some_method('my param', 'otherparam')

Both are equivalent.

Gustavo Niemeyer

More information about the testing-in-python mailing list