<div dir="ltr"> Hello,<br><br> 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.<br>
<br>--Scenario A--<br><br> The script being debugged is foo.py; its content is<br><code><br>print 'Hello, world!'<br></code><br><br> The "debugger" (a simplified version of it) is<br><code><br>
import bdb<br><br>g = {}<br>g['__name__'] = '__main__'<br>g['__file__'] = 'foo.py'<br>statement = 'execfile("%s", %s)' % ('foo.py', str(g))<br>bdb.Bdb().run(statement)<br>
</code><br><br>it indeed prints 'Hello, world'.<br><br>--Scenario B--<br>
<br>
The script being debugged is bar.py; its content is<br>
<code><br>import unittest<br><br>class test(unittest.TestCase):<br> def test(self):<br> print 'Hello, world!'<br><br>def suite():<br> return unittest.TestLoader().loadTestsFromTestCase(test)<br>
<br>if __name__ == '__main__':<br> unittest.main()<br></code><br><br> The "debugger" is identical to before, but with 'foo.py' replaced by 'bar.py'. It does not print 'Hello, world'. In fact, it prints<br>
<output><br>----------------------------------------------------------------------<br>Ran 0 tests in 0.000s<br></output><br><br> However:<br><ol><li>Running bar.py as a script, indeed prints 'Hello, world'. <br>
</li><li>Running pdb (which internally uses bdb.Bdb) on bar.py, also indeed prints 'Hello, world'. </li></ol><p> 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 appreciated.</p>
<p><br></p><p> Thanks & Bye,</p><p><br></p><p> Ami<br></p>
<br></div>