def debug_script(src, pm=False, globs=None):
 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)

def debug_script ( src , pm = False , globs = None ) : 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 )
debug a test script .