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.
This commit is contained in:
Tim Peters 2004-08-23 21:37:56 +00:00
parent 31bd529f53
commit b6a04d687d
1 changed files with 22 additions and 15 deletions

View File

@ -2342,11 +2342,15 @@ 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()
try:
if globs:
globs = globs.copy()
else:
@ -2363,6 +2367,9 @@ def debug_script(src, pm=False, globs=None):
# 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.