From f3e03fc298bbb10167ed0069f10ac67cde75dbbb Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 19 Nov 2012 14:07:14 +0100 Subject: [PATCH] modernize tmpdir fixture (use request.node in tmpdir fixture, use @pytest.fixture) --- _pytest/tmpdir.py | 6 +++--- testing/test_tmpdir.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/_pytest/tmpdir.py b/_pytest/tmpdir.py index 367d54e4e..3907c92b7 100644 --- a/_pytest/tmpdir.py +++ b/_pytest/tmpdir.py @@ -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 - diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index 7ed53e820..31dd1776d 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -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(""" @@ -16,12 +16,12 @@ def test_funcarg(testdir): # 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"