diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-08-23 21:37:56 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-08-23 21:37:56 (GMT) |
commit | b6a04d687da3803b7ed7434141a8d820d181f2a0 (patch) | |
tree | 941bbe24824595a8805ad548140d3e43810f7082 /Lib/doctest.py | |
parent | 31bd529f5307f65702dbe2a0accbb5532b188a5c (diff) | |
download | cpython-b6a04d687da3803b7ed7434141a8d820d181f2a0.zip cpython-b6a04d687da3803b7ed7434141a8d820d181f2a0.tar.gz cpython-b6a04d687da3803b7ed7434141a8d820d181f2a0.tar.bz2 |
debug_script(): I changed this in haste before to take out the use of
NamedTemporaryFile (which can't work for this function's purposes on
Windows). Leaving temp files behind wasn't a great idea either, though,
so try to clean up. At least the test suite no longer leaves any of
these guys behind now.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 4d1aa71..bcdc567 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -2342,26 +2342,33 @@ def debug_script(src, pm=False, globs=None): "Debug a test script. `src` is the script, as a string." import pdb - srcfilename = tempfile.mktemp("doctestdebug.py") + # Note that tempfile.NameTemporaryFile() cannot be used. As the + # docs say, a file so created cannot be opened by name a second time + # on modern Windows boxes, and execfile() needs to open it. + srcfilename = tempfile.mktemp(".py", "doctestdebug") f = open(srcfilename, 'w') f.write(src) f.close() - if globs: - globs = globs.copy() - else: - globs = {} + try: + if globs: + globs = globs.copy() + else: + globs = {} - if pm: - try: - execfile(srcfilename, globs, globs) - except: - print sys.exc_info()[1] - pdb.post_mortem(sys.exc_info()[2]) - else: - # Note that %r is vital here. '%s' instead can, e.g., cause - # backslashes to get treated as metacharacters on Windows. - pdb.run("execfile(%r)" % srcfilename, globs, globs) + if pm: + try: + execfile(srcfilename, globs, globs) + except: + print sys.exc_info()[1] + pdb.post_mortem(sys.exc_info()[2]) + else: + # Note that %r is vital here. '%s' instead can, e.g., cause + # backslashes to get treated as metacharacters on Windows. + pdb.run("execfile(%r)" % srcfilename, globs, globs) + + finally: + os.remove(srcfilename) def debug(module, name, pm=False): """Debug a single doctest docstring. |