modernize tmpdir fixture (use request.node in tmpdir fixture, use @pytest.fixture)
This commit is contained in:
parent
2ef350aede
commit
f3e03fc298
|
@ -54,15 +54,15 @@ def pytest_configure(config):
|
||||||
mp.setattr(config, '_tmpdirhandler', t, raising=False)
|
mp.setattr(config, '_tmpdirhandler', t, raising=False)
|
||||||
mp.setattr(pytest, 'ensuretemp', t.ensuretemp, 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
|
"""return a temporary directory path object
|
||||||
which is unique to each test function invocation,
|
which is unique to each test function invocation,
|
||||||
created as a sub directory of the base temporary
|
created as a sub directory of the base temporary
|
||||||
directory. The returned object is a `py.path.local`_
|
directory. The returned object is a `py.path.local`_
|
||||||
path object.
|
path object.
|
||||||
"""
|
"""
|
||||||
name = request._pyfuncitem.name
|
name = request.node.name
|
||||||
name = py.std.re.sub("[\W]", "_", name)
|
name = py.std.re.sub("[\W]", "_", name)
|
||||||
x = request.config._tmpdirhandler.mktemp(name, numbered=True)
|
x = request.config._tmpdirhandler.mktemp(name, numbered=True)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import py, pytest
|
import py, pytest
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from _pytest.tmpdir import pytest_funcarg__tmpdir, TempdirHandler
|
from _pytest.tmpdir import tmpdir, TempdirHandler
|
||||||
|
|
||||||
def test_funcarg(testdir):
|
def test_funcarg(testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
@ -16,12 +16,12 @@ def test_funcarg(testdir):
|
||||||
# pytest_unconfigure has deleted the TempdirHandler already
|
# pytest_unconfigure has deleted the TempdirHandler already
|
||||||
config = item.config
|
config = item.config
|
||||||
config._tmpdirhandler = TempdirHandler(config)
|
config._tmpdirhandler = TempdirHandler(config)
|
||||||
p = pytest_funcarg__tmpdir(item)
|
p = tmpdir(item._request)
|
||||||
assert p.check()
|
assert p.check()
|
||||||
bn = p.basename.strip("0123456789")
|
bn = p.basename.strip("0123456789")
|
||||||
assert bn.endswith("test_func_a_")
|
assert bn.endswith("test_func_a_")
|
||||||
item.name = "qwe/\\abc"
|
item.name = "qwe/\\abc"
|
||||||
p = pytest_funcarg__tmpdir(item)
|
p = tmpdir(item._request)
|
||||||
assert p.check()
|
assert p.check()
|
||||||
bn = p.basename.strip("0123456789")
|
bn = p.basename.strip("0123456789")
|
||||||
assert bn == "qwe__abc"
|
assert bn == "qwe__abc"
|
||||||
|
|
Loading…
Reference in New Issue