[Zope-dev] bug in zope.testing 3.7.1?

Marius Gedminas marius at gedmin.as
Mon Dec 22 08:27:51 EST 2008


On Fri, Dec 19, 2008 at 01:37:52PM -0500, Benji York wrote:
> On Fri, Dec 19, 2008 at 1:03 PM, Chris Withers <chris at simplistix.co.uk> wrote:
> > I have the following code that runs the tests in all my package's docs:
> >
> > def test_suite():
> >     suite = unittest.TestSuite()
> >     for path in \
> >      glob(os.path.join(os.path.dirname(__file__),'..','docs','*.txt')):
> >         suite.addTest(
> >             DocFileSuite(path, optionflags=REPORT_NDIFF|ELLIPSIS)
> >             )
> >     return suite
> 
> Paths to doctest files are relative to the calling module (by default).

To get them to accept paths relative to os.getcwd() (or absolute paths
for that matter), pass module_relative=False to DocFileSuite.

> Also, DocFileSuite can take multiple paths,

(I also always forget that.)

> so your function can be
> simplified to this:
> 
> def test_suite():
>     paths = glob(os.path.join('..', 'docs', '*.txt'))
>     return DocFileSuite(*paths, optionflags=REPORT_NDIFF|ELLIPSIS)
> 
> (You might want to use os.path.pardir instead of '..')

glob() will search relative to os.getcwd(), while DocFileSuite will
search relative to os.path.dirname(__file__).  The two may be different.

Marius Gedminas
-- 
http://pov.lt/ -- Zope 3 consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20081222/cdd779bb/attachment.bin 


More information about the Zope-Dev mailing list