Re: zope.testing.testrunner.debug.post_mortem and try/finally

Marius Gedminas <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <20091203144357.GA21094@platonas>
On Thu, Dec 03, 2009 at 03:51:06PM +0200, Marius Gedminas wrote:
> On Thu, Dec 03, 2009 at 08:55:32AM +0100, Wichert Akkerman wrote:
> > On 2009-12-2 23:06, Marius Gedminas wrote:
> > > On Wed, Dec 02, 2009 at 01:36:37PM -0500, Benji York wrote:
> > >> Here's another idea: a testrunner option that takes a file name and line
> > >> number and inserts a breakpoint at that position.  That way you can get
> > >> the same effect as editing the code without actually having to do so.
> > >
> > > Is that possible?  I once spent hours studying pdb docs and found no way
> > > to set a breakpoint in advance, without modifying the source file in
> > > question, and without having the user to do manual interaction at the
> > > beginning.
> > 
> > I think mr.freeze (see http://pypi.python.org/pypi/mr.freeze ) can do 
> > this.
> 
> Thank you for the link, this looks very interesting.
> 
> > Perhaps there is some code there you could borrow.
> 
> Or just depend and invoke it.

Better not, it pulls in too much stuff (WSGI and Zope 2 bits).

> AFAICS mr.freeze subclasses Pdb and
> rewires some of its internals in a nontrivial fashion to be able to do that:
> http://dev.plone.org/collective/browser/mr.freeze/trunk/mr/freeze/freeze.py

I've had some success with this:

import pdb

class SlightlyLessInsanePdb(pdb.Pdb):
    first_time = True
    def user_line(self, *a, **kw):
        if self.first_time:
            self.set_continue()
            self.first_time = False
        else:
            pdb.Pdb.user_line(self, *a, **kw)

def run_with_breakpoint(filename, lineno, func, *args, **kw):
    dbg = SlightlyLessInsanePdb()
    dbg.set_break(filename, lineno)
    return dbg.runcall(func, *args, **kw)


Marius Gedminas
-- 
http://pov.lt/ -- Zope 3 consulting and development

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFLF86tkVdEXeem148RAhVCAJ9msRdgZYzCCe7xTic1sNzH1CAxYgCffDub
804A0nBwMGeJCjvfGOy3CrE=
=C6h+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.