unittest in python: ignore an import from the code I want to test

Posted by vaidab on Stack Overflow See other posts from Stack Overflow or by vaidab
Published on 2010-06-15T13:38:43Z Indexed on 2010/06/15 13:42 UTC
Read the original article Hit count: 162

Filed under:
|

I have a python program that imports pythoncom (and uses pythoncom.CoCreateInstance from it). I want to create a unittest for the program logic without it importing pythoncom (so I can run the test on Linux as well).

What options are there? Can I do it without modifying the system under test?

What I found so far: sys.modules["pythoncom"] = "test" import module_that_imports_pythoncom

My problem with it is if I have: from pythoncom.something import something I'll get: ImportError: No module named something.something And sys.modules["something.something"] or sys.modules["pythoncom.something.something"] doesn't work.

Any ideas?

© Stack Overflow or respective owner

Related posts about python

Related posts about unit-testing