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@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