a much cleaner fix from Antoine
diff --git a/Lib/doctest.py b/Lib/doctest.py
index e2b595e..e8babd2 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -1360,10 +1360,8 @@
             linecache.getlines = self.save_linecache_getlines
             if clear_globs:
                 test.globs.clear()
-                if __name__ == "__main__":
-                    __builtins__._ = None
-                else:
-                    __builtins__['_'] = None
+                import builtins
+                builtins._ = None
 
     #/////////////////////////////////////////////////////////////////
     # Summarization