bdb.Bdb (Debugger Base Class) / unittest Interaction (MRAB)

Ami Tavory atavory at gmail.com
Mon Mar 26 04:15:09 EDT 2012


From: MRAB <python at mrabarnett.plus.com>
To: python-list at python.org
Cc:
Date: Sun, 25 Mar 2012 22:14:28 +0100
Subject: Re: bdb.Bdb (Debugger Base Class) / unittest Interaction
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>


----------------------------------------------------------------------------------------------------------------------------------------------------------

  Hi,

  Many thanks for your reply. Unfortunately, I'm consistently getting a
different output than yours on scenario B, namely
<output>
----------------------------------------------------------------------
Ran 0 tests in 0.000s
</output>
  This happens on separate computers, one running 2.6, and one running 2.7.
  Is it possible to ask whether you ran in scenario B bar.py or the
"debugger" running on bar.py? Running it through the "debugger" causes the
problem; without it it works fine. If the problem is only on my (two
separate) installations, is there something I can do to specify the problem
further?

  Thanks & Bye,

  Ami
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120326/57c36346/attachment.html>


More information about the Python-list mailing list