[Python-checkins] python/dist/src/Lib doctest.py, 1.36.2.23, 1.36.2.24

dcjim at users.sourceforge.net dcjim at users.sourceforge.net
Fri Aug 6 20:48:46 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24744
Modified Files:
 Tag: tim-doctest-branch
	doctest.py 
Log Message:
The debug runer was always clearing the test globs. We need to keep
them around if there is an error.
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.36.2.23
retrieving revision 1.36.2.24
diff -C2 -d -r1.36.2.23 -r1.36.2.24
*** doctest.py	6 Aug 2004 14:32:50 -0000	1.36.2.23
--- doctest.py	6 Aug 2004 18:48:43 -0000	1.36.2.24
***************
*** 1586,1589 ****
--- 1586,1594 ----
 self.got = got
 
+ def __str__(self):
+ return str(self.test)
+ 
+ 
+ 
 class DebugRunner(DocTestRunner):
 r"""Run doc tests but raise an exception as soon as there is a failure.
***************
*** 1626,1631 ****
--- 1631,1676 ----
 >>> failure.got
 '1\n'
+ 
+ If a failure or error occurs, the globals are left intact:
+ 
+ >>> del test.globs['__builtins__']
+ >>> test.globs
+ {'x': 1}
+ 
+ >>> test = DocTest('''
+ ... >>> x = 2
+ ... >>> raise KeyError
+ ... ''', {}, 'foo', 'foo.py', 0)
+ 
+ >>> runner.run(test)
+ Traceback (most recent call last):
+ ...
+ KeyError
+ 
+ >>> del test.globs['__builtins__']
+ >>> test.globs
+ {'x': 2}
+ 
+ But the globals are cleared if there is no error:
+ 
+ >>> test = DocTest('''
+ ... >>> x = 2
+ ... ''', {}, 'foo', 'foo.py', 0)
+ 
+ >>> runner.run(test)
+ (0, 1)
+ 
+ >>> test.globs
+ {}
+ 
+ 
 """
 
+ def run(self, test, compileflags=None, out=None, clear_globs=True):
+ r = DocTestRunner.run(self, test, compileflags, out, False)
+ if clear_globs:
+ test.globs.clear()
+ return r
+ 
 def report_unexpected_exception(self, out, test, example, exc_info):
 raise exc_info[0], exc_info[1], exc_info[2]


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /