[TIP] TestFixtures 1.8.0 Released!
chris at simplistix.co.uk
Fri Jan 14 06:49:16 PST 2011
On 14/01/2011 14:39, Jack Keegan wrote:
> objects. In particular, at the moment, testing some code that needs to
> access hardware IOs using DLLs. I do this using Ctypes.
> However, on my dev machine, I don't have the same hardware so calling
> the DLL functions will not work as expected. Therefore I'd like to mock
> out the ctypes dll calls. Can you give me an indication of how you would
> go about doing this with TestFixtures? Just so you know, I use py.test for
> unit testing.
I've not used ctypes myself so let me know if things don't work ;-)
I'd suggest developing mock objects to work in place of your ctypes
objects. You may well find that if you're just wanting to test that the
right calls are made you can use an existing mock objects such as:
...and then compare the method_calls attribute of the mock with what you
expect it to be.
TestFixtures provides some handy tools for managing the insertion and
removal of mock objects, read here:
Simplistix - Content Management, Batch Processing & Python Consulting
More information about the testing-in-python