On 25/03/2012 21:42, Ami Tavory wrote:
   Hello,

   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 foo.py; its content is
<code>
print 'Hello, world!'
</code>

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

g = {}
g['__name__'] = '__main__'
g['__file__'] = 'foo.py'
statement = 'execfile("%s", %s)' % ('foo.py', str(g))
bdb.Bdb().run(statement)
</code>

it indeed prints 'Hello, world'.

--Scenario B--

   The script being debugged is bar.py; its content is
<code>
import unittest

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

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

if __name__ == '__main__':
     unittest.main()
</code>

   The "debugger" is identical to before, but with 'foo.py' replaced by
'bar.py'. It does not print 'Hello, world'. In fact, it prints
<output>
----------------------------------------------------------------------
Ran 0 tests in 0.000s
</output>

  However:

 1. Running bar.py as a script, indeed prints 'Hello, world'.
 2. Running pdb (which internally uses bdb.Bdb) on bar.py, 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 appreciated.

With Python 2.7 I'm getting this:

<stdout>
Hello, world!
</stdout>

<stderr>
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
</stderr>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to