Remove 'tmpdir_factory.ensuretemp'
This commit is contained in:
parent
7e58defc15
commit
aa1955de72
|
@ -13,6 +13,8 @@ removed:
|
||||||
|
|
||||||
* ``pytest.config`` global variable.
|
* ``pytest.config`` global variable.
|
||||||
|
|
||||||
|
* ``tmpdir_factory.ensuretemp`` method.
|
||||||
|
|
||||||
|
|
||||||
For more information consult
|
For more information consult
|
||||||
`Deprecations and Removals <https://docs.pytest.org/en/latest/deprecations.html>`__ in the docs.
|
`Deprecations and Removals <https://docs.pytest.org/en/latest/deprecations.html>`__ in the docs.
|
||||||
|
|
|
@ -9,7 +9,6 @@ All constants defined in this module should be either PytestWarning instances or
|
||||||
in case of warnings which need to format their messages.
|
in case of warnings which need to format their messages.
|
||||||
"""
|
"""
|
||||||
from _pytest.warning_types import PytestDeprecationWarning
|
from _pytest.warning_types import PytestDeprecationWarning
|
||||||
from _pytest.warning_types import RemovedInPytest4Warning
|
|
||||||
|
|
||||||
YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
|
YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
|
||||||
|
|
||||||
|
@ -46,11 +45,6 @@ RESULT_LOG = PytestDeprecationWarning(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
PYTEST_ENSURETEMP = RemovedInPytest4Warning(
|
|
||||||
"pytest/tmpdir_factory.ensuretemp is deprecated, \n"
|
|
||||||
"please use the tmp_path fixture or tmp_path_factory.mktemp"
|
|
||||||
)
|
|
||||||
|
|
||||||
PYTEST_LOGWARNING = PytestDeprecationWarning(
|
PYTEST_LOGWARNING = PytestDeprecationWarning(
|
||||||
"pytest_logwarning is deprecated, no longer being called, and will be removed soon\n"
|
"pytest_logwarning is deprecated, no longer being called, and will be removed soon\n"
|
||||||
"please use pytest_warning_captured instead"
|
"please use pytest_warning_captured instead"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
import warnings
|
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
import py
|
import py
|
||||||
|
@ -85,19 +84,6 @@ class TempdirFactory:
|
||||||
|
|
||||||
_tmppath_factory = attr.ib()
|
_tmppath_factory = attr.ib()
|
||||||
|
|
||||||
def ensuretemp(self, string, dir=1):
|
|
||||||
""" (deprecated) return temporary directory path with
|
|
||||||
the given string as the trailing part. It is usually
|
|
||||||
better to use the 'tmpdir' function argument which
|
|
||||||
provides an empty unique-per-test-invocation directory
|
|
||||||
and is guaranteed to be empty.
|
|
||||||
"""
|
|
||||||
# py.log._apiwarn(">1.1", "use tmpdir function argument")
|
|
||||||
from .deprecated import PYTEST_ENSURETEMP
|
|
||||||
|
|
||||||
warnings.warn(PYTEST_ENSURETEMP, stacklevel=2)
|
|
||||||
return self.getbasetemp().ensure(string, dir=dir)
|
|
||||||
|
|
||||||
def mktemp(self, basename, numbered=True):
|
def mktemp(self, basename, numbered=True):
|
||||||
"""Create a subdirectory of the base temporary directory and return it.
|
"""Create a subdirectory of the base temporary directory and return it.
|
||||||
If ``numbered``, ensure the directory is unique by adding a number
|
If ``numbered``, ensure the directory is unique by adding a number
|
||||||
|
@ -135,7 +121,6 @@ def pytest_configure(config):
|
||||||
config._cleanup.append(mp.undo)
|
config._cleanup.append(mp.undo)
|
||||||
mp.setattr(config, "_tmp_path_factory", tmppath_handler, raising=False)
|
mp.setattr(config, "_tmp_path_factory", tmppath_handler, raising=False)
|
||||||
mp.setattr(config, "_tmpdirhandler", t, raising=False)
|
mp.setattr(config, "_tmpdirhandler", t, raising=False)
|
||||||
mp.setattr(pytest, "ensuretemp", t.ensuretemp, raising=False)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
|
|
|
@ -14,13 +14,6 @@ def test_tmpdir_fixture(testdir):
|
||||||
results.stdout.fnmatch_lines(["*1 passed*"])
|
results.stdout.fnmatch_lines(["*1 passed*"])
|
||||||
|
|
||||||
|
|
||||||
def test_ensuretemp(recwarn):
|
|
||||||
d1 = pytest.ensuretemp("hello")
|
|
||||||
d2 = pytest.ensuretemp("hello")
|
|
||||||
assert d1 == d2
|
|
||||||
assert d1.check(dir=1)
|
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class FakeConfig:
|
class FakeConfig:
|
||||||
basetemp = attr.ib()
|
basetemp = attr.ib()
|
||||||
|
@ -85,12 +78,15 @@ def test_basetemp(testdir):
|
||||||
p = testdir.makepyfile(
|
p = testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
def test_1():
|
def test_1(tmpdir_factory):
|
||||||
pytest.ensuretemp("hello")
|
tmpdir_factory.mktemp('hello', numbered=False)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest(p, "--basetemp=%s" % mytemp, SHOW_PYTEST_WARNINGS_ARG)
|
result = testdir.runpytest(
|
||||||
|
p, "--basetemp=%s" % mytemp, SHOW_PYTEST_WARNINGS_ARG, "-s"
|
||||||
|
)
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
print(mytemp)
|
||||||
assert mytemp.join("hello").check()
|
assert mytemp.join("hello").check()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue