Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
unittest.TestCase.__init__(self)
self._dt_optionflags = optionflags
self._dt_checker = checker
self._dt_globs = test.globs.copy()
self._dt_test = test
self._dt_setUp = setUp
self._dt_tearDown = tearDown
Expand All @@ -2187,7 +2188,9 @@ def tearDown(self):
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
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,22 @@ def test_no_trailing_whitespace_stripping():
"""


def test_run_doctestsuite_multiple_times():
"""
It was not possible to run the same DocTestSuite multiple times
http://bugs.python.org/issue2604
http://bugs.python.org/issue9736

>>> import unittest
>>> import test.sample_doctest
>>> suite = doctest.DocTestSuite(test.sample_doctest)
>>> suite.run(unittest.TestResult())
<unittest.result.TestResult run=9 errors=0 failures=4>
>>> suite.run(unittest.TestResult())
<unittest.result.TestResult run=9 errors=0 failures=4>
"""


def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite(doctest))
tests.addTest(doctest.DocTestSuite())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where doctests using globals would fail when run multiple times.