[py-dev] how to configure additional traceback cut-out

holger krekel holger at merlinux.eu
Sun Jan 17 21:16:03 CET 2010


On Sun, Jan 17, 2010 at 20:49 +0100, Ronny Pfannschmidt wrote:
> On Sun, 2010-01-17 at 20:25 +0100, holger krekel wrote:
> > Hi Ronny, 
> > 
> > On Sun, Jan 17, 2010 at 18:53 +0100, Ronny Pfannschmidt wrote:
> > > hi,
> > > 
> > > while debugging vim-dbus use, 
> > > i'd like to remove all those nasty line-nosie alike traceback iems  from
> > > the python dbus libs as they don't really help the traceback.
> > > 
> > > Is there any way to do that right now or does it need invention.
> > 
> > No way yet.  The "__tracebackhide__ = True" setting only works for code
> > you control, obviously.  
> > 
> > However, the internal ExceptionInfo() object has support for processing
> > tracebacks so i guess we could add a hook that you can use like this:
> > 
> >     # ./conftest.py
> >     def pytest_filter_traceback(excinfo):
> >         dbuspath = py.path.local(dbus.__file__).dirpath()
> >         excinfo.traceback = excinfo.traceback.filter(
> >             lambda entry: not entry.path.relto(dbuspath))
> > 
> > This hook should not be called when "--tb=full" is specified, i guess.
> > 
> > makes sense to you? 
> > 
> that looks very sensible, i'll take a look at where to put that, 
> seems like traceback pruning is somewhere in collect
> 
> since its about filtering tracebacks,
> how about having it take a traceback and return one
> so one could do something like:
> 
> def pytest_filter_traceback(traceback):
>    dbuspath = py.path.local(dbus.__file__).dirpath()
>    return traceback.filter(lambda entry: not entry.path.relto(dbuspath))

This would inhibit having multiple hooks involved. There is no
hook-call mode which allows to "chain", so far it wasn't 
strictly needed. 

Adding pytest_filter_traceback to py/_plugin/hookspec.py 
and shifting the traceback.filter() call in pycollect.py::_prunetraceback 
to a default hook in py/_plugin/pytest_default.py and adding
a self.ihook.pytest_filter_traceback(excinfo=excinfo) instead should 
be enough to allow a custom conftest.py hook.  And of course a test in 
testing/test_pycollect.py::TestConftestCustomization

cheers,
holger



More information about the Pytest-dev mailing list