"""Deprecation messages and bits of code used elsewhere in the codebase that is planned to be removed in the next pytest release. Keeping it in a central location makes it easy to track what is deprecated and should be removed when the time comes. All constants defined in this module should be either instances of :class:`PytestWarning`, or :class:`UnformattedWarning` in case of warnings which need to format their messages. """ from __future__ import annotations from warnings import warn from _pytest.warning_types import PytestDeprecationWarning from _pytest.warning_types import PytestRemovedIn10Warning from _pytest.warning_types import UnformattedWarning # set of plugins which have been integrated into the core; we use this list to ignore # them during registration to avoid conflicts DEPRECATED_EXTERNAL_PLUGINS = { "pytest_catchlog", "pytest_capturelog", "pytest_faulthandler", "pytest_subtests", } # This could have been removed pytest 8, but it's harmless and common, so no rush to remove. YIELD_FIXTURE = PytestDeprecationWarning( "@pytest.yield_fixture is deprecated.\n" "Use @pytest.fixture instead; they are the same." ) # This deprecation is never really meant to be removed. PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.") HOOK_LEGACY_MARKING = UnformattedWarning( PytestRemovedIn10Warning, "The hook{type} {fullname} uses old-style configuration options (marks or attributes).\n" "Please use the pytest.hook{type}({hook_opts}) decorator instead\n" " to configure the hooks.\n" " See https://docs.pytest.org/en/latest/deprecations.html" "#configuring-hook-specs-impls-using-markers", ) MONKEYPATCH_LEGACY_NAMESPACE_PACKAGES = PytestRemovedIn10Warning( "monkeypatch.syspath_prepend() called with pkg_resources legacy namespace packages detected.\n" "Legacy namespace packages (using pkg_resources.declare_namespace) are deprecated.\n" "Please use native namespace packages (PEP 420) instead.\n" "See https://docs.pytest.org/en/stable/deprecations.html#monkeypatch-fixup-namespace-packages" ) PARAMETRIZE_NON_COLLECTION_ITERABLE = UnformattedWarning( PytestRemovedIn10Warning, "Passing a non-Collection iterable to parametrize is deprecated.\n" "Test: {nodeid}, argvalues type: {type_name}\n" "Please convert to a list or tuple.\n" "See https://docs.pytest.org/en/stable/deprecations.html#parametrize-iterators", ) CONFIG_INICFG = PytestRemovedIn10Warning( "config.inicfg is deprecated, use config.getini() to access configuration values instead.\n" "See https://docs.pytest.org/en/stable/deprecations.html#config-inicfg" ) FIXTURE_GETFIXTUREVALUE_DURING_TEARDOWN = UnformattedWarning( PytestRemovedIn10Warning, 'Calling request.getfixturevalue("{argname}") during teardown is deprecated.\n' "Please request the fixture before teardown begins, either by declaring it in the fixture signature " "or by calling request.getfixturevalue() before the fixture yields.\n" "See https://docs.pytest.org/en/stable/deprecations.html#dynamic-fixture-request-during-teardown", ) # You want to make some `__init__` or function "private". # # def my_private_function(some, args): # ... # # Do this: # # def my_private_function(some, args, *, _ispytest: bool = False): # check_ispytest(_ispytest) # ... # # Change all internal/allowed calls to # # my_private_function(some, args, _ispytest=True) # # All other calls will get the default _ispytest=False and trigger # the warning (possibly error in the future). def check_ispytest(ispytest: bool) -> None: if not ispytest: warn(PRIVATE, stacklevel=3)