From aa1955de72dbca1a907d4692487f707da14b5d96 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 30 Jun 2019 12:27:29 -0300 Subject: [PATCH] Remove 'tmpdir_factory.ensuretemp' --- changelog/5180.removal.rst | 2 ++ src/_pytest/deprecated.py | 6 ------ src/_pytest/tmpdir.py | 15 --------------- testing/test_tmpdir.py | 16 ++++++---------- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/changelog/5180.removal.rst b/changelog/5180.removal.rst index 49f896f94..dfe9c5f8d 100644 --- a/changelog/5180.removal.rst +++ b/changelog/5180.removal.rst @@ -13,6 +13,8 @@ removed: * ``pytest.config`` global variable. +* ``tmpdir_factory.ensuretemp`` method. + For more information consult `Deprecations and Removals `__ in the docs. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 2c853d48b..58ffee1ae 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -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. """ 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" @@ -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 is deprecated, no longer being called, and will be removed soon\n" "please use pytest_warning_captured instead" diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index f2c4d905c..c7a61b0d4 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -2,7 +2,6 @@ import os import re import tempfile -import warnings import attr import py @@ -85,19 +84,6 @@ class TempdirFactory: _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): """Create a subdirectory of the base temporary directory and return it. If ``numbered``, ensure the directory is unique by adding a number @@ -135,7 +121,6 @@ def pytest_configure(config): config._cleanup.append(mp.undo) mp.setattr(config, "_tmp_path_factory", tmppath_handler, raising=False) mp.setattr(config, "_tmpdirhandler", t, raising=False) - mp.setattr(pytest, "ensuretemp", t.ensuretemp, raising=False) @pytest.fixture(scope="session") diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index c4c7ebe25..f11ddbe68 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -14,13 +14,6 @@ def test_tmpdir_fixture(testdir): 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 class FakeConfig: basetemp = attr.ib() @@ -85,12 +78,15 @@ def test_basetemp(testdir): p = testdir.makepyfile( """ import pytest - def test_1(): - pytest.ensuretemp("hello") + def test_1(tmpdir_factory): + 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 + print(mytemp) assert mytemp.join("hello").check()