Skip to content

Commit 9828cfa

Browse files
authored
Merge pull request #7117 from bluetech/deprecate-fillfuncargs-v2
fixtures: deprecate pytest._fillfuncargs function
2 parents cbca9f1 + 289e6c1 commit 9828cfa

File tree

8 files changed

+41
-6
lines changed

8 files changed

+41
-6
lines changed

changelog/7097.deprecation.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The ``pytest._fillfuncargs`` function is now deprecated. This function was kept
2+
for backward compatibility with an older plugin.
3+
4+
It's functionality is not meant to be used directly, but if you must replace
5+
it, use `function._request._fillfixtures()` instead, though note this is not
6+
a public API and may break in the future.

doc/en/deprecations.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Below is a complete list of all pytest features which are considered deprecated.
2020
:ref:`standard warning filters <warnings>`.
2121

2222

23+
The ``pytest._fillfuncargs`` function
24+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
26+
.. deprecated:: 5.5
27+
28+
This function was kept for backward compatibility with an older plugin.
29+
30+
It's functionality is not meant to be used directly, but if you must replace
31+
it, use `function._request._fillfixtures()` instead, though note this is not
32+
a public API and may break in the future.
33+
34+
35+
2336
``--no-print-logs`` command-line option
2437
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2538

src/_pytest/deprecated.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
"since pytest 2.3 - use the newer attribute instead."
2626
)
2727

28+
FILLFUNCARGS = PytestDeprecationWarning(
29+
"The `_fillfuncargs` function is deprecated, use "
30+
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
31+
)
32+
2833
RESULT_LOG = PytestDeprecationWarning(
2934
"--result-log is deprecated, please try the new pytest-reportlog plugin.\n"
3035
"See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information."

src/_pytest/fixtures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from _pytest.compat import NOTSET
2929
from _pytest.compat import safe_getattr
3030
from _pytest.compat import TYPE_CHECKING
31+
from _pytest.deprecated import FILLFUNCARGS
3132
from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS
3233
from _pytest.deprecated import FUNCARGNAMES
3334
from _pytest.mark import ParameterSet
@@ -276,6 +277,7 @@ def reorder_items_atscope(items, argkeys_cache, items_by_argkey, scopenum):
276277

277278
def fillfixtures(function):
278279
""" fill missing funcargs for a test function. """
280+
warnings.warn(FILLFUNCARGS, stacklevel=2)
279281
try:
280282
request = function._request
281283
except AttributeError:

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ def setup(self) -> None:
15351535
if isinstance(self.parent, Instance):
15361536
self.parent.newinstance()
15371537
self.obj = self._getobj()
1538-
fixtures.fillfixtures(self)
1538+
self._request._fillfixtures()
15391539

15401540
def _prunetraceback(self, excinfo: ExceptionInfo) -> None:
15411541
if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False):

testing/deprecated_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
from unittest import mock
23

34
import pytest
45
from _pytest import deprecated
@@ -146,3 +147,11 @@ def test_foo():
146147
)
147148

148149
assert_no_print_logs(testdir, ())
150+
151+
152+
def test__fillfuncargs_is_deprecated() -> None:
153+
with pytest.warns(
154+
pytest.PytestDeprecationWarning,
155+
match="The `_fillfuncargs` function is deprecated",
156+
):
157+
pytest._fillfuncargs(mock.Mock())

testing/python/fixtures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_detect_recursive_dependency_error(self, testdir):
110110
def test_funcarg_basic(self, testdir):
111111
testdir.copy_example()
112112
item = testdir.getitem(Path("test_funcarg_basic.py"))
113-
fixtures.fillfixtures(item)
113+
item._request._fillfixtures()
114114
del item.funcargs["request"]
115115
assert len(get_public_names(item.funcargs)) == 2
116116
assert item.funcargs["some"] == "test_func"
@@ -664,7 +664,7 @@ def test_func(something): pass
664664
assert val2 == 2
665665
val2 = req.getfixturevalue("other") # see about caching
666666
assert val2 == 2
667-
pytest._fillfuncargs(item)
667+
item._request._fillfixtures()
668668
assert item.funcargs["something"] == 1
669669
assert len(get_public_names(item.funcargs)) == 2
670670
assert "request" in item.funcargs
@@ -681,7 +681,7 @@ def test_func(something): pass
681681
"""
682682
)
683683
item.session._setupstate.prepare(item)
684-
pytest._fillfuncargs(item)
684+
item._request._fillfixtures()
685685
# successively check finalization calls
686686
teardownlist = item.getparent(pytest.Module).obj.teardownlist
687687
ss = item.session._setupstate

testing/python/integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class TestOEJSKITSpecials:
7-
def test_funcarg_non_pycollectobj(self, testdir): # rough jstests usage
7+
def test_funcarg_non_pycollectobj(self, testdir, recwarn): # rough jstests usage
88
testdir.makeconftest(
99
"""
1010
import pytest
@@ -34,7 +34,7 @@ class MyClass(object):
3434
pytest._fillfuncargs(clscol)
3535
assert clscol.funcargs["arg1"] == 42
3636

37-
def test_autouse_fixture(self, testdir): # rough jstests usage
37+
def test_autouse_fixture(self, testdir, recwarn): # rough jstests usage
3838
testdir.makeconftest(
3939
"""
4040
import pytest

0 commit comments

Comments
 (0)