Skip to content

Commit

Permalink
modernize tmpdir fixture (use request.node in tmpdir fixture, use @py…
Browse files Browse the repository at this point in the history
…test.fixture)
  • Loading branch information
hpk42 committed Nov 19, 2012
1 parent 2ef350a commit f3e03fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions _pytest/tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def pytest_configure(config):
mp.setattr(config, '_tmpdirhandler', t, raising=False)
mp.setattr(pytest, 'ensuretemp', t.ensuretemp, raising=False)

def pytest_funcarg__tmpdir(request):
@pytest.fixture
def tmpdir(request):
"""return a temporary directory path object
which is unique to each test function invocation,
created as a sub directory of the base temporary
directory. The returned object is a `py.path.local`_
path object.
"""
name = request._pyfuncitem.name
name = request.node.name
name = py.std.re.sub("[\W]", "_", name)
x = request.config._tmpdirhandler.mktemp(name, numbered=True)
return x

6 changes: 3 additions & 3 deletions testing/test_tmpdir.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import py, pytest
import os

from _pytest.tmpdir import pytest_funcarg__tmpdir, TempdirHandler
from _pytest.tmpdir import tmpdir, TempdirHandler

def test_funcarg(testdir):
testdir.makepyfile("""
Expand All @@ -16,12 +16,12 @@ def test_func(tmpdir): pass
# pytest_unconfigure has deleted the TempdirHandler already
config = item.config
config._tmpdirhandler = TempdirHandler(config)
p = pytest_funcarg__tmpdir(item)
p = tmpdir(item._request)
assert p.check()
bn = p.basename.strip("0123456789")
assert bn.endswith("test_func_a_")
item.name = "qwe/\\abc"
p = pytest_funcarg__tmpdir(item)
p = tmpdir(item._request)
assert p.check()
bn = p.basename.strip("0123456789")
assert bn == "qwe__abc"
Expand Down

0 comments on commit f3e03fc

Please sign in to comment.