[py-dev] How do I access current testing directory?

holger krekel hpk at trillke.net
Wed Dec 22 08:37:29 CET 2004


Hi Kevin, 

On Tue, Dec 21, 2004 at 17:47 -0500, Kevin Smith wrote:

> Great great testing program. What a time saver, very
> pythonic.  

thanks!   

> My question is how do I access the current
> working directory (where the test is located) from within
> the test?

    mytestfile = py.magic.autopath() 

gives you the test file itself as a path object.  Of course, 
you could also look at the usual module __file__ string but this 
would not work for remote path objects.  (py.test allows to run 
tests from svn repositories without downloading etc.pp). 

You may want to use path objects with 

    datadir = py.magic.autopath().dirpath().join('data')
    content1 = datadir.join('data1').read()

etc.pp. which will of course also work for remote svn urls.  I
guess i finally need to write some documentation about path 
objects ... 

cheers, 

    holger



More information about the Pytest-dev mailing list