Add alias clarification to deprecation warning (#7829)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
		
							parent
							
								
									dc96e485a0
								
							
						
					
					
						commit
						c93962c491
					
				| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Improve deprecation warning message for ``pytest._fillfuncargs()``.
 | 
				
			||||||
| 
						 | 
					@ -20,9 +20,10 @@ DEPRECATED_EXTERNAL_PLUGINS = {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FILLFUNCARGS = PytestDeprecationWarning(
 | 
					FILLFUNCARGS = UnformattedWarning(
 | 
				
			||||||
    "The `_fillfuncargs` function is deprecated, use "
 | 
					    PytestDeprecationWarning,
 | 
				
			||||||
    "function._request._fillfixtures() instead if you cannot avoid reaching into internals."
 | 
					    "{name} is deprecated, use "
 | 
				
			||||||
 | 
					    "function._request._fillfixtures() instead if you cannot avoid reaching into internals.",
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PYTEST_COLLECT_MODULE = UnformattedWarning(
 | 
					PYTEST_COLLECT_MODULE = UnformattedWarning(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -339,9 +339,22 @@ def reorder_items_atscope(
 | 
				
			||||||
    return items_done
 | 
					    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:
 | 
					def fillfixtures(function: "Function") -> None:
 | 
				
			||||||
    """Fill missing funcargs for a test function."""
 | 
					    """Fill missing fixtures for a test function (deprecated)."""
 | 
				
			||||||
    warnings.warn(FILLFUNCARGS, stacklevel=2)
 | 
					    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:
 | 
					    try:
 | 
				
			||||||
        request = function._request
 | 
					        request = function._request
 | 
				
			||||||
    except AttributeError:
 | 
					    except AttributeError:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ from _pytest.config import hookspec
 | 
				
			||||||
from _pytest.config import main
 | 
					from _pytest.config import main
 | 
				
			||||||
from _pytest.config import UsageError
 | 
					from _pytest.config import UsageError
 | 
				
			||||||
from _pytest.debugging import pytestPDB as __pytestPDB
 | 
					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 fixture
 | 
				
			||||||
from _pytest.fixtures import FixtureLookupError
 | 
					from _pytest.fixtures import FixtureLookupError
 | 
				
			||||||
from _pytest.fixtures import yield_fixture
 | 
					from _pytest.fixtures import yield_fixture
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
import warnings
 | 
					import warnings
 | 
				
			||||||
from unittest import mock
 | 
					from unittest import mock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,11 +27,27 @@ def test_external_plugins_integrated(testdir, plugin):
 | 
				
			||||||
def test_fillfuncargs_is_deprecated() -> None:
 | 
					def test_fillfuncargs_is_deprecated() -> None:
 | 
				
			||||||
    with pytest.warns(
 | 
					    with pytest.warns(
 | 
				
			||||||
        pytest.PytestDeprecationWarning,
 | 
					        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())
 | 
					        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:
 | 
					def test_minus_k_dash_is_deprecated(testdir) -> None:
 | 
				
			||||||
    threepass = testdir.makepyfile(
 | 
					    threepass = testdir.makepyfile(
 | 
				
			||||||
        test_threepass="""
 | 
					        test_threepass="""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,7 +87,7 @@ def test_getfuncargnames_staticmethod_partial():
 | 
				
			||||||
class TestFillFixtures:
 | 
					class TestFillFixtures:
 | 
				
			||||||
    def test_fillfuncargs_exposed(self):
 | 
					    def test_fillfuncargs_exposed(self):
 | 
				
			||||||
        # used by oejskit, kept for compatibility
 | 
					        # used by oejskit, kept for compatibility
 | 
				
			||||||
        assert pytest._fillfuncargs == fixtures.fillfixtures
 | 
					        assert pytest._fillfuncargs == fixtures._fillfuncargs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_funcarg_lookupfails(self, testdir):
 | 
					    def test_funcarg_lookupfails(self, testdir):
 | 
				
			||||||
        testdir.copy_example()
 | 
					        testdir.copy_example()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue