bdb.Bdb (Debugger Base Class) / unittest Interaction

Ami Tavory atavory at
Sun Mar 25 22:42:52 CEST 2012


  I'm having some difficulties with the interaction between bdb.Bdb and
scripts which contain unittest. Following are two simplified scenarios of a
GUI debugger Gedit plugin I'm writing based on bdb.Bdb, and a script that
is being debugged by it.

--Scenario A--

  The script being debugged is; its content is
print 'Hello, world!'

  The "debugger" (a simplified version of it) is
import bdb

g = {}
g['__name__'] = '__main__'
g['__file__'] = ''
statement = 'execfile("%s", %s)' % ('', str(g))

it indeed prints 'Hello, world'.

--Scenario B--

  The script being debugged is; its content is
import unittest

class test(unittest.TestCase):
    def test(self):
        print 'Hello, world!'

def suite():
    return unittest.TestLoader().loadTestsFromTestCase(test)

if __name__ == '__main__':

  The "debugger" is identical to before, but with '' replaced by
''. It does not print 'Hello, world'. In fact, it prints
Ran 0 tests in 0.000s


   1. Running as a script, indeed prints 'Hello, world'.
   2. Running pdb (which internally uses bdb.Bdb) on, also indeed
   prints 'Hello, world'.

  I've looked at the code of pdb to see what I'm doing wrong (at least in
the second case), but couldn't find the difference. Help would be much

  Thanks & Bye,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list