summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-03-22 21:27:26 (GMT)
committerGitHub <noreply@github.com>2022-03-22 21:27:26 (GMT)
commit3c6019035f16b673cf0f0be6918f7d5493e5690e (patch)
treec1064f24928eb1fe30539435ae48947a6863cec8 /Lib
parentaf341ebf00d9a45cadea4c07810564d8e8962b96 (diff)
downloadcpython-3c6019035f16b673cf0f0be6918f7d5493e5690e.zip
cpython-3c6019035f16b673cf0f0be6918f7d5493e5690e.tar.gz
cpython-3c6019035f16b673cf0f0be6918f7d5493e5690e.tar.bz2
bpo-2604: Make doctest.DocTestCase reset globs in teardown (GH-31932)
Co-authored-by: Piet Delport Co-authored-by: Hugo Lopes Tavares Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 7ba7eae50803b11766421cb8aae1780058a57e2b) Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/doctest.py3
-rw-r--r--Lib/test/test_doctest.py16
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index d2c8828..3caf4d9 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -2159,6 +2159,7 @@ class DocTestCase(unittest.TestCase):
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
@@ -2175,7 +2176,9 @@ class DocTestCase(unittest.TestCase):
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
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 47b8575..dba1910 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -3107,6 +3107,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())