Skip to content

Commit 95fd566

Browse files
authored
Merge pull request #7867 from nicoddemus/backport-7829
2 parents dc96e48 + c93962c commit 95fd566

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

Diff for: changelog/7815.doc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve deprecation warning message for ``pytest._fillfuncargs()``.

Diff for: src/_pytest/deprecated.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
}
2121

2222

23-
FILLFUNCARGS = PytestDeprecationWarning(
24-
"The `_fillfuncargs` function is deprecated, use "
25-
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
23+
FILLFUNCARGS = UnformattedWarning(
24+
PytestDeprecationWarning,
25+
"{name} is deprecated, use "
26+
"function._request._fillfixtures() instead if you cannot avoid reaching into internals.",
2627
)
2728

2829
PYTEST_COLLECT_MODULE = UnformattedWarning(

Diff for: src/_pytest/fixtures.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,22 @@ def reorder_items_atscope(
339339
return items_done
340340

341341

342+
def _fillfuncargs(function: "Function") -> None:
343+
"""Fill missing fixtures for a test function, old public API (deprecated)."""
344+
warnings.warn(FILLFUNCARGS.format(name="pytest._fillfuncargs()"), stacklevel=2)
345+
_fill_fixtures_impl(function)
346+
347+
342348
def fillfixtures(function: "Function") -> None:
343-
"""Fill missing funcargs for a test function."""
344-
warnings.warn(FILLFUNCARGS, stacklevel=2)
349+
"""Fill missing fixtures for a test function (deprecated)."""
350+
warnings.warn(
351+
FILLFUNCARGS.format(name="_pytest.fixtures.fillfixtures()"), stacklevel=2
352+
)
353+
_fill_fixtures_impl(function)
354+
355+
356+
def _fill_fixtures_impl(function: "Function") -> None:
357+
"""Internal implementation to fill fixtures on the given function object."""
345358
try:
346359
request = function._request
347360
except AttributeError:

Diff for: src/pytest/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from _pytest.config import main
1212
from _pytest.config import UsageError
1313
from _pytest.debugging import pytestPDB as __pytestPDB
14-
from _pytest.fixtures import fillfixtures as _fillfuncargs
14+
from _pytest.fixtures import _fillfuncargs
1515
from _pytest.fixtures import fixture
1616
from _pytest.fixtures import FixtureLookupError
1717
from _pytest.fixtures import yield_fixture

Diff for: testing/deprecated_test.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import warnings
23
from unittest import mock
34

@@ -26,11 +27,27 @@ def test_external_plugins_integrated(testdir, plugin):
2627
def test_fillfuncargs_is_deprecated() -> None:
2728
with pytest.warns(
2829
pytest.PytestDeprecationWarning,
29-
match="The `_fillfuncargs` function is deprecated",
30+
match=re.escape(
31+
"pytest._fillfuncargs() is deprecated, use "
32+
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
33+
),
3034
):
3135
pytest._fillfuncargs(mock.Mock())
3236

3337

38+
def test_fillfixtures_is_deprecated() -> None:
39+
import _pytest.fixtures
40+
41+
with pytest.warns(
42+
pytest.PytestDeprecationWarning,
43+
match=re.escape(
44+
"_pytest.fixtures.fillfixtures() is deprecated, use "
45+
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
46+
),
47+
):
48+
_pytest.fixtures.fillfixtures(mock.Mock())
49+
50+
3451
def test_minus_k_dash_is_deprecated(testdir) -> None:
3552
threepass = testdir.makepyfile(
3653
test_threepass="""

Diff for: testing/python/fixtures.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class T:
8787
class TestFillFixtures:
8888
def test_fillfuncargs_exposed(self):
8989
# used by oejskit, kept for compatibility
90-
assert pytest._fillfuncargs == fixtures.fillfixtures
90+
assert pytest._fillfuncargs == fixtures._fillfuncargs
9191

9292
def test_funcarg_lookupfails(self, testdir):
9393
testdir.copy_example()

0 commit comments

Comments
 (0)