Add a missing check before deleting a package's __loader__.
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index e96785c..f53a759 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -1922,7 +1922,8 @@
          ...                                  package='test')
          ...     suite.run(unittest.TestResult())
          ... finally:
-         ...     del test.__loader__
+         ...     if added_loader:
+         ...         del test.__loader__
          <unittest.TestResult run=3 errors=0 failures=3>
 
        '/' should be used as a path separator.  It will be converted