I have a Python module that tries to import a module, and if it fails, adds sets up a lightweight class to replicate some of the functionality as a fallback.
How can I write a unit test that covers both cases - when the module is present, and when the module is not present?
try:
from foo import bar
except:
class myFakeBar(object):
def doAThing(self):
return "blah"
For example, if bar is present, the unit tests will report that only the 2nd line is covered, and the rest of the module isn't.
Aucun commentaire:
Enregistrer un commentaire