Skip to content
Ignoring revisions in .git-blame-ignore-revs.

Latest commit

 

History

History
99 lines (80 loc) · 3.62 KB

File metadata and controls

99 lines (80 loc) · 3.62 KB
 
Aug 1, 2020
Aug 1, 2020
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.
Sep 14, 2018
Sep 14, 2018
6
Mar 5, 2020
Mar 5, 2020
7
All constants defined in this module should be either instances of
8
:class:`PytestWarning`, or :class:`UnformattedWarning`
Sep 14, 2018
Sep 14, 2018
9
in case of warnings which need to format their messages.
Jan 30, 2024
Jan 30, 2024
11
Jun 20, 2024
Jun 20, 2024
12
from __future__ import annotations
13
Nov 13, 2020
Nov 13, 2020
14
from warnings import warn
15
Oct 26, 2018
Oct 26, 2018
16
from _pytest.warning_types import PytestDeprecationWarning
Oct 13, 2025
Oct 13, 2025
17
from _pytest.warning_types import PytestRemovedIn10Warning
Nov 23, 2019
Nov 23, 2019
18
from _pytest.warning_types import UnformattedWarning
Sep 14, 2018
Sep 14, 2018
19
Feb 2, 2024
Feb 2, 2024
20
Jun 22, 2019
Jun 22, 2019
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",
Nov 1, 2025
Nov 1, 2025
27
"pytest_subtests",
Jun 22, 2019
Jun 22, 2019
28
}
29
Jun 25, 2019
Jun 25, 2019
30
Oct 3, 2025
Oct 3, 2025
31
# This could have been removed pytest 8, but it's harmless and common, so no rush to remove.
Nov 7, 2020
Nov 7, 2020
32
YIELD_FIXTURE = PytestDeprecationWarning(
33
"@pytest.yield_fixture is deprecated.\n"
34
"Use @pytest.fixture instead; they are the same."
35
)
Mar 30, 2020
Mar 30, 2020
36
Nov 14, 2021
Nov 14, 2021
37
# This deprecation is never really meant to be removed.
Nov 13, 2020
Nov 13, 2020
38
PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")
39
40
Sep 20, 2022
Sep 20, 2022
41
HOOK_LEGACY_MARKING = UnformattedWarning(
Mar 6, 2021
Mar 6, 2021
42
PytestDeprecationWarning,
Sep 20, 2022
Sep 20, 2022
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",
Mar 6, 2021
Mar 6, 2021
48
)
49
Oct 13, 2025
Oct 13, 2025
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
Nov 5, 2025
Nov 5, 2025
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
Nov 13, 2025
Nov 13, 2025
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
Mar 16, 2026
Mar 16, 2026
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
Nov 13, 2020
Nov 13, 2020
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).
Mar 6, 2021
Mar 6, 2021
95
96
Nov 13, 2020
Nov 13, 2020
97
def check_ispytest(ispytest: bool) -> None:
98
if not ispytest:
99
warn(PRIVATE, stacklevel=3)