2528 |
2529 |
2530 |
2531 |
2532 |
2533 |
2534 |
2535 |
2536 |
2537 |
2538 |
2539 |
2540 |
2541 |
2542 |
2543 |
2544 |
2545 |
2546 |
2547 |
2548 |
2549 |
2550 |
2551 |
2552 |
2553 |
2554 |
2555 |
2556 |
2557 |
2558 | |
def debug_script(src, pm=False, globs=None): |
"Debug a test script. `src` is the script, as a string." |
import pdb |
|
|
|
|
srcfilename = tempfile.mktemp(".py", "doctestdebug") |
f = open(srcfilename, 'w') |
f.write(src) |
f.close() |
|
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: |
|
|
pdb.run("execfile(%r)" % srcfilename, globs, globs) |
|
finally: |
os.remove(srcfilename) | |