0

In my code I have:

try:     
    import json 
except ImportError:     
    import simplejson as json 

Coverage says that the ImportError isn' tested. How do I go about writing a proper unittest to test this particular failure?

NewGuy
  • 3,273
  • 7
  • 43
  • 61
  • Given that `json` ships with Python, how would `simplejson` ever get used? – jonrsharpe Mar 05 '16 at 21:12
  • Which import is used is based on your environment. Strictly seens that brings them out of the scope off unit testing. Basically you should consider if testing is required. Is there a case, where the import could fail and no other test would fail as well? I guess not. – Klaus D. Mar 05 '16 at 21:13
  • @jonrsharpe On old Python version without the json package. Before 2.5 AFAIR. – Klaus D. Mar 05 '16 at 21:14
  • 1
    @KlausD. Ah; *"New in version 2.6"* apparently. – jonrsharpe Mar 05 '16 at 21:15

0 Answers0