2009-02-27 18:18:27 +08:00
|
|
|
"""
|
|
|
|
example:
|
|
|
|
|
|
|
|
pytest_plugins = "pytest_tmpdir"
|
|
|
|
|
|
|
|
def test_plugin(tmpdir):
|
|
|
|
tmpdir.join("hello").write("hello")
|
|
|
|
|
|
|
|
"""
|
|
|
|
import py
|
|
|
|
|
|
|
|
class TmpdirPlugin:
|
|
|
|
""" provide temporary directories to test functions and methods.
|
|
|
|
"""
|
|
|
|
|
2009-04-15 00:30:26 +08:00
|
|
|
def pytest_funcarg__tmpdir(self, request):
|
2009-04-15 01:57:00 +08:00
|
|
|
name = request.function.__name__
|
2009-04-15 00:30:26 +08:00
|
|
|
return request.config.mktemp(name, numbered=True)
|
2009-02-27 18:18:27 +08:00
|
|
|
|
|
|
|
# ===============================================================================
|
|
|
|
#
|
|
|
|
# plugin tests
|
|
|
|
#
|
|
|
|
# ===============================================================================
|
|
|
|
#
|
|
|
|
def test_generic(plugintester):
|
2009-05-08 00:01:53 +08:00
|
|
|
plugintester.hookcheck(TmpdirPlugin)
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-03-26 17:16:30 +08:00
|
|
|
def test_funcarg(testdir):
|
2009-02-27 18:18:27 +08:00
|
|
|
item = testdir.getitem("def test_func(tmpdir): pass")
|
|
|
|
plugin = TmpdirPlugin()
|
2009-04-15 00:30:26 +08:00
|
|
|
p = plugin.pytest_funcarg__tmpdir(item.getrequest("tmpdir"))
|
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")
|