Skip to content

Commit

Permalink
Merge pull request #7867 from nicoddemus/backport-7829
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored Oct 6, 2020
2 parents dc96e48 + c93962c commit 95fd566
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog/7815.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve deprecation warning message for ``pytest._fillfuncargs()``.
7 changes: 4 additions & 3 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
}


FILLFUNCARGS = PytestDeprecationWarning(
"The `_fillfuncargs` function is deprecated, use "
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
FILLFUNCARGS = UnformattedWarning(
PytestDeprecationWarning,
"{name} is deprecated, use "
"function._request._fillfixtures() instead if you cannot avoid reaching into internals.",
)

PYTEST_COLLECT_MODULE = UnformattedWarning(
Expand Down
17 changes: 15 additions & 2 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,22 @@ def reorder_items_atscope(
return items_done


def _fillfuncargs(function: "Function") -> None:
"""Fill missing fixtures for a test function, old public API (deprecated)."""
warnings.warn(FILLFUNCARGS.format(name="pytest._fillfuncargs()"), stacklevel=2)
_fill_fixtures_impl(function)


def fillfixtures(function: "Function") -> None:
"""Fill missing funcargs for a test function."""
warnings.warn(FILLFUNCARGS, stacklevel=2)
"""Fill missing fixtures for a test function (deprecated)."""
warnings.warn(
FILLFUNCARGS.format(name="_pytest.fixtures.fillfixtures()"), stacklevel=2
)
_fill_fixtures_impl(function)


def _fill_fixtures_impl(function: "Function") -> None:
"""Internal implementation to fill fixtures on the given function object."""
try:
request = function._request
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion src/pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from _pytest.config import main
from _pytest.config import UsageError
from _pytest.debugging import pytestPDB as __pytestPDB
from _pytest.fixtures import fillfixtures as _fillfuncargs
from _pytest.fixtures import _fillfuncargs
from _pytest.fixtures import fixture
from _pytest.fixtures import FixtureLookupError
from _pytest.fixtures import yield_fixture
Expand Down
19 changes: 18 additions & 1 deletion testing/deprecated_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import warnings
from unittest import mock

Expand Down Expand Up @@ -26,11 +27,27 @@ def test_external_plugins_integrated(testdir, plugin):
def test_fillfuncargs_is_deprecated() -> None:
with pytest.warns(
pytest.PytestDeprecationWarning,
match="The `_fillfuncargs` function is deprecated",
match=re.escape(
"pytest._fillfuncargs() is deprecated, use "
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
),
):
pytest._fillfuncargs(mock.Mock())


def test_fillfixtures_is_deprecated() -> None:
import _pytest.fixtures

with pytest.warns(
pytest.PytestDeprecationWarning,
match=re.escape(
"_pytest.fixtures.fillfixtures() is deprecated, use "
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
),
):
_pytest.fixtures.fillfixtures(mock.Mock())


def test_minus_k_dash_is_deprecated(testdir) -> None:
threepass = testdir.makepyfile(
test_threepass="""
Expand Down
2 changes: 1 addition & 1 deletion testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class T:
class TestFillFixtures:
def test_fillfuncargs_exposed(self):
# used by oejskit, kept for compatibility
assert pytest._fillfuncargs == fixtures.fillfixtures
assert pytest._fillfuncargs == fixtures._fillfuncargs

def test_funcarg_lookupfails(self, testdir):
testdir.copy_example()
Expand Down

0 comments on commit 95fd566

Please sign in to comment.