Index: Lib/doctest.py =================================================================== --- Lib/doctest.py (revision 62386) +++ Lib/doctest.py (working copy) @@ -2089,6 +2089,7 @@ self._dt_optionflags = optionflags self._dt_checker = checker self._dt_test = test + self._dt_globs = test.globs.copy() self._dt_setUp = setUp self._dt_tearDown = tearDown @@ -2104,7 +2105,9 @@ if self._dt_tearDown is not None: self._dt_tearDown(test) + # restore the original globs test.globs.clear() + test.globs.update(self._dt_globs) def runTest(self): test = self._dt_test Index: Lib/test/test_doctest.py =================================================================== --- Lib/test/test_doctest.py (revision 62386) +++ Lib/test/test_doctest.py (working copy) @@ -1880,7 +1880,7 @@ Here, we didn't need to use a tearDown function because we modified the test globals, which are a copy of the sample_doctest module dictionary. The test globals are - automatically cleared for us after a test. + automatically reset for us after a test. """ def test_DocFileSuite(): @@ -2026,7 +2026,7 @@ Here, we didn't need to use a tearDown function because we modified the test globals. The test globals are - automatically cleared for us after a test. + automatically reset for us after a test. Tests in a file run using `DocFileSuite` can also access the `__file__` global, which is set to the name of the file