-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathdeprecated.py
More file actions
Ignoring revisions in .git-blame-ignore-revs.
99 lines (80 loc) · 3.62 KB
/
deprecated.py
File metadata and controls
99 lines (80 loc) · 3.62 KB
Edit and raw actions
OlderNewer
1
"""Deprecation messages and bits of code used elsewhere in the codebase that
2
is planned to be removed in the next pytest release.
3
4
Keeping it in a central location makes it easy to track what is deprecated and should
5
be removed when the time comes.
6
7
All constants defined in this module should be either instances of
8
:class:`PytestWarning`, or :class:`UnformattedWarning`
9
in case of warnings which need to format their messages.
10
"""
11
12
from __future__ import annotations
13
14
from warnings import warn
15
16
from _pytest.warning_types import PytestDeprecationWarning
17
from _pytest.warning_types import PytestRemovedIn10Warning
18
from _pytest.warning_types import UnformattedWarning
19
20
21
# set of plugins which have been integrated into the core; we use this list to ignore
22
# them during registration to avoid conflicts
23
DEPRECATED_EXTERNAL_PLUGINS = {
24
"pytest_catchlog",
25
"pytest_capturelog",
26
"pytest_faulthandler",
27
"pytest_subtests",
28
}
29
30
31
# This could have been removed pytest 8, but it's harmless and common, so no rush to remove.
32
YIELD_FIXTURE = PytestDeprecationWarning(
33
"@pytest.yield_fixture is deprecated.\n"
34
"Use @pytest.fixture instead; they are the same."
35
)
36
37
# This deprecation is never really meant to be removed.
38
PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")
39
40
41
HOOK_LEGACY_MARKING = UnformattedWarning(
42
PytestDeprecationWarning,
43
"The hook{type} {fullname} uses old-style configuration options (marks or attributes).\n"
44
"Please use the pytest.hook{type}({hook_opts}) decorator instead\n"
45
" to configure the hooks.\n"
46
" See https://docs.pytest.org/en/latest/deprecations.html"
47
"#configuring-hook-specs-impls-using-markers",
48
)
49
50
MONKEYPATCH_LEGACY_NAMESPACE_PACKAGES = PytestRemovedIn10Warning(
51
"monkeypatch.syspath_prepend() called with pkg_resources legacy namespace packages detected.\n"
52
"Legacy namespace packages (using pkg_resources.declare_namespace) are deprecated.\n"
53
"Please use native namespace packages (PEP 420) instead.\n"
54
"See https://docs.pytest.org/en/stable/deprecations.html#monkeypatch-fixup-namespace-packages"
55
)
56
57
PARAMETRIZE_NON_COLLECTION_ITERABLE = UnformattedWarning(
58
PytestRemovedIn10Warning,
59
"Passing a non-Collection iterable to parametrize is deprecated.\n"
60
"Test: {nodeid}, argvalues type: {type_name}\n"
61
"Please convert to a list or tuple.\n"
62
"See https://docs.pytest.org/en/stable/deprecations.html#parametrize-iterators",
63
)
64
65
CONFIG_INICFG = PytestRemovedIn10Warning(
66
"config.inicfg is deprecated, use config.getini() to access configuration values instead.\n"
67
"See https://docs.pytest.org/en/stable/deprecations.html#config-inicfg"
68
)
69
70
FIXTURE_GETFIXTUREVALUE_DURING_TEARDOWN = UnformattedWarning(
71
PytestRemovedIn10Warning,
72
'Calling request.getfixturevalue("{argname}") during teardown is deprecated.\n'
73
"Please request the fixture before teardown begins, either by declaring it in the fixture signature "
74
"or by calling request.getfixturevalue() before the fixture yields.\n"
75
"See https://docs.pytest.org/en/stable/deprecations.html#dynamic-fixture-request-during-teardown",
76
)
77
78
# You want to make some `__init__` or function "private".
79
#
80
# def my_private_function(some, args):
81
# ...
82
#
83
# Do this:
84
#
85
# def my_private_function(some, args, *, _ispytest: bool = False):
86
# check_ispytest(_ispytest)
87
# ...
88
#
89
# Change all internal/allowed calls to
90
#
91
# my_private_function(some, args, _ispytest=True)
92
#
93
# All other calls will get the default _ispytest=False and trigger
94
# the warning (possibly error in the future).
95
96
97
def check_ispytest(ispytest: bool) -> None:
98
if not ispytest:
99
warn(PRIVATE, stacklevel=3)