From 5381e1cbf0bc7065d930ac7675f566119eb022d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Mari=C3=B1ez?= Date: Fri, 2 Oct 2020 07:18:08 -0400 Subject: [PATCH 1/3] Add alias clarification to deprecation warning --- changelog/7815.doc.rst | 1 + src/_pytest/deprecated.py | 2 +- testing/deprecated_test.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelog/7815.doc.rst diff --git a/changelog/7815.doc.rst b/changelog/7815.doc.rst new file mode 100644 index 00000000000..1295795170e --- /dev/null +++ b/changelog/7815.doc.rst @@ -0,0 +1 @@ +Added alias clarification on the deprecation warning for `_fillfuncargs` function. \ No newline at end of file diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index ecdb60d37f5..0ce8c2702e7 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -21,7 +21,7 @@ FILLFUNCARGS = PytestDeprecationWarning( - "The `_fillfuncargs` function is deprecated, use " + "The `_fillfuncargs` function (public alias of _pytest.fixtures.fillfixtures function) is deprecated, use " "function._request._fillfixtures() instead if you cannot avoid reaching into internals." ) diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index eb5d527f52b..9903d954950 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -26,7 +26,8 @@ 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="The `_fillfuncargs` function (public alias of _pytest.fixtures.fillfixtures function) is deprecated, use " + "function._request._fillfixtures() instead if you cannot avoid reaching into internals.", ): pytest._fillfuncargs(mock.Mock()) From 96da4a2a437f9abb6da57b813f0391b28c9a1953 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 4 Oct 2020 08:35:32 -0300 Subject: [PATCH 2/3] Improve pytest._fillfuncargs() deprecation message --- changelog/7815.doc.rst | 2 +- src/_pytest/deprecated.py | 4 ++-- src/_pytest/fixtures.py | 9 +++++++-- src/pytest/__init__.py | 2 +- testing/deprecated_test.py | 7 +++++-- testing/python/fixtures.py | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/changelog/7815.doc.rst b/changelog/7815.doc.rst index 1295795170e..d799bb42500 100644 --- a/changelog/7815.doc.rst +++ b/changelog/7815.doc.rst @@ -1 +1 @@ -Added alias clarification on the deprecation warning for `_fillfuncargs` function. \ No newline at end of file +Improve deprecation warning message for ``pytest._fillfuncargs()``. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 0ce8c2702e7..d22166da1d6 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -21,8 +21,8 @@ FILLFUNCARGS = PytestDeprecationWarning( - "The `_fillfuncargs` function (public alias of _pytest.fixtures.fillfixtures function) is deprecated, use " - "function._request._fillfixtures() instead if you cannot avoid reaching into internals." + "pytest._fillfuncargs() is deprecated, use " + "_pytest.fixtures.fillfixtures() instead if you cannot avoid reaching into internals." ) PYTEST_COLLECT_MODULE = UnformattedWarning( diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index f526f484b29..286436aee0c 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -339,9 +339,14 @@ def reorder_items_atscope( return items_done -def fillfixtures(function: "Function") -> None: - """Fill missing funcargs for a test function.""" +def _fillfuncargs(function: "Function") -> None: + """Fill missing fixtures for a test function (deprecated).""" warnings.warn(FILLFUNCARGS, stacklevel=2) + fillfixtures(function) + + +def fillfixtures(function: "Function") -> None: + """Fill missing fixtures for a test function.""" try: request = function._request except AttributeError: diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index c4c28191877..a9c1ee0282b 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -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 diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 9903d954950..3d78a5ad8b0 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -1,3 +1,4 @@ +import re import warnings from unittest import mock @@ -26,8 +27,10 @@ def test_external_plugins_integrated(testdir, plugin): def test_fillfuncargs_is_deprecated() -> None: with pytest.warns( pytest.PytestDeprecationWarning, - match="The `_fillfuncargs` function (public alias of _pytest.fixtures.fillfixtures function) is deprecated, use " - "function._request._fillfixtures() instead if you cannot avoid reaching into internals.", + match=re.escape( + "pytest._fillfuncargs() is deprecated, use " + "_pytest.fixtures.fillfixtures() instead if you cannot avoid reaching into internals." + ), ): pytest._fillfuncargs(mock.Mock()) diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 9ae5a91db43..67b7ad60116 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -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() From 5ad03510f5979c86c0a972587b9a2e44b30fdab2 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 5 Oct 2020 10:26:58 -0300 Subject: [PATCH 3/3] Deprecate _pytest.fixtures.fillfixtures too --- src/_pytest/deprecated.py | 7 ++++--- src/_pytest/fixtures.py | 16 ++++++++++++---- testing/deprecated_test.py | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index d22166da1d6..fd00fe2d6d5 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -20,9 +20,10 @@ } -FILLFUNCARGS = PytestDeprecationWarning( - "pytest._fillfuncargs() is deprecated, use " - "_pytest.fixtures.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( diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 286436aee0c..a299b2dba50 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -340,13 +340,21 @@ def reorder_items_atscope( def _fillfuncargs(function: "Function") -> None: - """Fill missing fixtures for a test function (deprecated).""" - warnings.warn(FILLFUNCARGS, stacklevel=2) - fillfixtures(function) + """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 fixtures for a test function.""" + """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: diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 3d78a5ad8b0..5fe9ad7305f 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -29,12 +29,25 @@ def test_fillfuncargs_is_deprecated() -> None: pytest.PytestDeprecationWarning, match=re.escape( "pytest._fillfuncargs() is deprecated, use " - "_pytest.fixtures.fillfixtures() instead if you cannot avoid reaching into internals." + "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="""