[TIP] TestFixtures 1.8.0 Released!

Chris Withers chris at simplistix.co.uk
Fri Jan 14 06:49:16 PST 2011


Hi Jack,

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:

http://pypi.python.org/pypi/mock/

...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:

http://packages.python.org/testfixtures/mocking.html

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
            - http://www.simplistix.co.uk



More information about the testing-in-python mailing list