Make trace and doctest play nice together (issue 1429818).  Will backport.
diff --git a/Lib/doctest.py b/Lib/doctest.py
index e874a26..3c977e1 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -320,8 +320,19 @@
     """
     def __init__(self, out):
         self.__out = out
+        self.__debugger_used = False
         pdb.Pdb.__init__(self, stdout=out)
 
+    def set_trace(self):
+        self.__debugger_used = True
+        pdb.Pdb.set_trace(self)
+
+    def set_continue(self):
+        # Calling set_continue unconditionally would break unit test
+        # coverage reporting, as Bdb.set_continue calls sys.settrace(None).
+        if self.__debugger_used:
+            pdb.Pdb.set_continue(self)
+
     def trace_dispatch(self, *args):
         # Redirect stdout to the given stream.
         save_stdout = sys.stdout