2010-07-27 03:15:15 +08:00
|
|
|
"""provide temporary directories to test functions.
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-11-05 10:18:55 +08:00
|
|
|
usage example::
|
2009-02-27 18:18:27 +08:00
|
|
|
|
|
|
|
def test_plugin(tmpdir):
|
|
|
|
tmpdir.join("hello").write("hello")
|
|
|
|
|
2009-11-05 10:18:55 +08:00
|
|
|
.. _`py.path.local`: ../../path.html
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
"""
|
|
|
|
import py
|
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_funcarg__tmpdir(request):
|
2009-11-05 10:18:55 +08:00
|
|
|
"""return a temporary directory path object
|
|
|
|
unique to each test function invocation,
|
|
|
|
created as a sub directory of the base temporary
|
|
|
|
directory. The returned object is a `py.path.local`_
|
2010-07-27 03:15:15 +08:00
|
|
|
path object.
|
2009-11-05 10:18:55 +08:00
|
|
|
"""
|
2010-07-27 03:15:15 +08:00
|
|
|
name = request.function.__name__
|
2009-11-13 04:15:59 +08:00
|
|
|
x = request.config.mktemp(name, numbered=True)
|
|
|
|
return x.realpath()
|