[TIP] flexmock for Python

Herman Sheremetyev herman at swebpage.com
Wed Nov 24 05:27:16 PST 2010


Hello python testers,

Over the last few weeks I've been working on a new mocking library for
Python, largely inspired by Ruby's flexmock -- although I didn't go
for full feature parity with the Ruby version. The syntax is very
simple but powerful and allows for some fairly interesting assertion
patterns.

It's available from:

https://github.com/has207/flexmock

To give a few reasons why you might be interested, here's a list of
currently supported features:

- unittest.TestCase integration
- automatic expectation checking on tearDown
- should_receive()
- with_args() ['with' is reserved in python]
- times() [as well as once, twice and never aliases]
- and_return()
- and_raise()
- overriding new instances (on new-style objects)
- parameter shortcuts for with_args/and_return
- at_least/at_most expectation modifiers
- proxying/spying using the pass_thru expectation modifier

More complete usage docs available at:

https://github.com/has207/flexmock/wiki/Documentation

It's still evolving as I'm adding more features, but I'd be really
interested in any feedback from the community.

Cheers,

-Herman



More information about the testing-in-python mailing list