[py-dev] running doctest-based tests

holger krekel hpk at trillke.net
Wed Jun 8 15:51:38 CEST 2005


On Wed, Jun 08, 2005 at 14:18 +0300, Max Ischenko wrote:
> > I have doctests in my source code which I want to have executed by
> py.test.
> > 
> > From what I understood, I need to add a conftest.py to my source package
> > directory and specify some collector that is able to collect and run these
> > tests.
> 
> I have made some progress in implementing it myself but stuck with some
> mysterious error.
> 
> I assume that the Item, when encounter a failure must raise a corresponding
> Outcome exception (which get caught by runtraced() method in session module.
> 
> In my case, it got caught but then py.test breaks nevertheless and shows a
> traceback that point to my raise Failed() statement. Somehow it continues to
> think of my code as part of client code, that as library code. This is my
> guess, at least.

I think the code is basically fine (i had a feeling of deja-vu, did you
take this code from some py-dev posting? just curious ...).  

However, item.run() methods currently doesn't have direct means to control 
output in case of a test failure.  What we should do, i guess, is 
to say that an explicit 'py.test.skip()' doesn't print any traceback 
(maybe controlable by some command-line argument). Instead it prints 
only the given message.  You could then extend your doctest approach 
to produce the message you want py.test to show.  

cheers, 

    holger



More information about the Pytest-dev mailing list