Python and Mock

So, last week I was happily mocking away and nothing seemed to be a problem. This week I ran into a part of program that makes mocking hard: properties.

For the background, I’m currently using Mock framework by Michael Foord and Konrad Delong for mocking in Python. The framework is really nice and hardly ever gets your way of working, until you run into properties.

In the manual, two different solutions are given. One of them is to subclass Mock, define needed property on this new class and use Mock to track the calls. Another option is to use patching.

These do get the work done, but both look somewhat messy in the test code. For now, I have settled working on subclassing Mock and defining needed properties there.

.Net and Moq

On the .Net side of the things, I have started playing around on Moq. It’s simple to use and support .Net 3.5. After some initial trial and error, using it has proven to be pretty straightforward. I’ll write more about our experiences when I’ll use it some more.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s