Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22145 > unrolled thread

Re: bdb.Bdb (Debugger Base Class) / unittest Interaction

Started byMRAB <python@mrabarnett.plus.com>
First post2012-03-25 22:14 +0100
Last post2012-03-25 22:14 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: bdb.Bdb (Debugger Base Class) / unittest Interaction MRAB <python@mrabarnett.plus.com> - 2012-03-25 22:14 +0100

#22145 — Re: bdb.Bdb (Debugger Base Class) / unittest Interaction

FromMRAB <python@mrabarnett.plus.com>
Date2012-03-25 22:14 +0100
SubjectRe: bdb.Bdb (Debugger Base Class) / unittest Interaction
Message-ID<mailman.972.1332710080.3037.python-list@python.org>
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>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web