diff --git a/xdoctest/__main__.py b/xdoctest/__main__.py
index <HASH>..<HASH> 100644
--- a/xdoctest/__main__.py
+++ b/xdoctest/__main__.py
@@ -147,7 +147,7 @@ def main():
     run_summary = xdoctest.doctest_module(modname, argv=[command], style=style,
                                           verbose=config['verbose'],
                                           config=config, durations=durations)
-    n_failed = run_summary['n_failed']
+    n_failed = run_summary.get('n_failed', 0)
     if n_failed > 0:
         sys.exit(1)
     else:
Default n_failed to 0