Show deprecation warning for cached_setup

This commit is contained in:
Bruno Oliveira 2018-09-13 14:25:46 -03:00
parent bf074b37a3
commit 482bd5efd2
4 changed files with 31 additions and 0 deletions

View File

@ -6,3 +6,6 @@ The following accesses have been documented as deprecated for years, but are now
usage of Function.Module is deprecated, please use pytest.Module instead
Users should just ``import pytest`` and access those objects using the ``pytest`` module.
* ``request.cached_setup``, this was the precursor of the setup/teardown mechanism available to fixtures. You can
consult `funcarg comparision section in the docs <https://docs.pytest.org/en/latest/funcarg_compare.html>`_.

View File

@ -479,6 +479,11 @@ class FixtureRequest(FuncargnamesCompatAttr):
or ``session`` indicating the caching lifecycle of the resource.
:arg extrakey: added to internal caching key of (funcargname, scope).
"""
msg = (
"cached_setup is deprecated and will be removed in a future release. "
"Use standard fixture functions instead."
)
warnings.warn(RemovedInPytest4Warning(msg), stacklevel=2)
if not hasattr(self.config, "_setupcache"):
self.config._setupcache = {} # XXX weakref?
cachekey = (self.fixturename, self._getscopeitem(scope), extrakey)

View File

@ -47,6 +47,27 @@ def test_compat_properties_deprecation(testdir):
)
def test_cached_setup_deprecation(testdir):
testdir.makepyfile(
"""
import pytest
@pytest.fixture
def fix(request):
return request.cached_setup(lambda: 1)
def test_foo(fix):
assert fix == 1
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
[
"*test_cached_setup_deprecation.py:4:*cached_setup is deprecated*",
"*1 passed, 1 warnings in*",
]
)
@pytest.mark.filterwarnings("default")
def test_funcarg_prefix_deprecation(testdir):
testdir.makepyfile(

View File

@ -977,6 +977,7 @@ class TestRequestCachedSetup(object):
)
reprec.assertoutcome(passed=4)
@pytest.mark.filterwarnings("ignore:cached_setup is deprecated")
def test_request_cachedsetup_extrakey(self, testdir):
item1 = testdir.getitem("def test_func(): pass")
req1 = fixtures.FixtureRequest(item1)
@ -994,6 +995,7 @@ class TestRequestCachedSetup(object):
assert ret1 == ret1b
assert ret2 == ret2b
@pytest.mark.filterwarnings("ignore:cached_setup is deprecated")
def test_request_cachedsetup_cache_deletion(self, testdir):
item1 = testdir.getitem("def test_func(): pass")
req1 = fixtures.FixtureRequest(item1)