Given code like this in somemod.py
:
try:
Import cStringIO as StringIO
except ImportError:
import StringIO
How can one test the 'fallback' branch?
(Use case: trying to achieve 100% coverage. Agreed that this is a bit of a silly goal :) )
Complications:
- code runs from
test_somemod.py
which hasimport somemod
- Mocking ImportError in Python covers some of this, but is complicated!