2009-02-27 18:18:27 +08:00
|
|
|
"""
|
2009-05-19 05:26:16 +08:00
|
|
|
provide temporary directories to test functions and methods.
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
example:
|
|
|
|
|
|
|
|
pytest_plugins = "pytest_tmpdir"
|
|
|
|
|
|
|
|
def test_plugin(tmpdir):
|
|
|
|
tmpdir.join("hello").write("hello")
|
|
|
|
|
|
|
|
"""
|
|
|
|
import py
|
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_funcarg__tmpdir(request):
|
|
|
|
name = request.function.__name__
|
|
|
|
return request.config.mktemp(name, numbered=True)
|
2009-02-27 18:18:27 +08:00
|
|
|
|
|
|
|
# ===============================================================================
|
|
|
|
#
|
|
|
|
# plugin tests
|
|
|
|
#
|
|
|
|
# ===============================================================================
|
|
|
|
#
|
|
|
|
def test_generic(plugintester):
|
2009-05-19 05:26:16 +08:00
|
|
|
plugintester.hookcheck()
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-03-26 17:16:30 +08:00
|
|
|
def test_funcarg(testdir):
|
2009-05-12 01:23:57 +08:00
|
|
|
from py.__.test.funcargs import FuncargRequest
|
2009-02-27 18:18:27 +08:00
|
|
|
item = testdir.getitem("def test_func(tmpdir): pass")
|
2009-05-21 15:45:43 +08:00
|
|
|
p = pytest_funcarg__tmpdir(FuncargRequest(item))
|
2009-02-27 18:18:27 +08:00
|
|
|
assert p.check()
|
2009-03-17 21:10:17 +08:00
|
|
|
bn = p.basename.strip("0123456789-")
|
2009-03-01 19:24:52 +08:00
|
|
|
assert bn.endswith("test_func")
|