Coverage for /opt/homebrew/lib/python3.11/site-packages/_pytest/deprecated.py: 96%
24 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-05-04 13:14 +0700
« prev ^ index » next coverage.py v7.2.3, created at 2023-05-04 13:14 +0700
1"""Deprecation messages and bits of code used elsewhere in the codebase that
2is planned to be removed in the next pytest release.
4Keeping it in a central location makes it easy to track what is deprecated and should
5be removed when the time comes.
7All constants defined in this module should be either instances of
8:class:`PytestWarning`, or :class:`UnformattedWarning`
9in case of warnings which need to format their messages.
10"""
11from warnings import warn
13from _pytest.warning_types import PytestDeprecationWarning
14from _pytest.warning_types import PytestRemovedIn8Warning
15from _pytest.warning_types import UnformattedWarning
17# set of plugins which have been integrated into the core; we use this list to ignore
18# them during registration to avoid conflicts
19DEPRECATED_EXTERNAL_PLUGINS = {
20 "pytest_catchlog",
21 "pytest_capturelog",
22 "pytest_faulthandler",
23}
25NOSE_SUPPORT = UnformattedWarning(
26 PytestRemovedIn8Warning,
27 "Support for nose tests is deprecated and will be removed in a future release.\n"
28 "{nodeid} is using nose method: `{method}` ({stage})\n"
29 "See docs: https://docs.pytest.org/en/stable/deprecations.html#support-for-tests-written-for-nose",
30)
32NOSE_SUPPORT_METHOD = UnformattedWarning(
33 PytestRemovedIn8Warning,
34 "Support for nose tests is deprecated and will be removed in a future release.\n"
35 "{nodeid} is using nose-specific method: `{method}(self)`\n"
36 "To remove this warning, rename it to `{method}_method(self)`\n"
37 "See docs: https://docs.pytest.org/en/stable/deprecations.html#support-for-tests-written-for-nose",
38)
41# This can be* removed pytest 8, but it's harmless and common, so no rush to remove.
42# * If you're in the future: "could have been".
43YIELD_FIXTURE = PytestDeprecationWarning(
44 "@pytest.yield_fixture is deprecated.\n"
45 "Use @pytest.fixture instead; they are the same."
46)
48WARNING_CMDLINE_PREPARSE_HOOK = PytestRemovedIn8Warning(
49 "The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n"
50 "Please use pytest_load_initial_conftests hook instead."
51)
53FSCOLLECTOR_GETHOOKPROXY_ISINITPATH = PytestRemovedIn8Warning(
54 "The gethookproxy() and isinitpath() methods of FSCollector and Package are deprecated; "
55 "use self.session.gethookproxy() and self.session.isinitpath() instead. "
56)
58STRICT_OPTION = PytestRemovedIn8Warning(
59 "The --strict option is deprecated, use --strict-markers instead."
60)
62# This deprecation is never really meant to be removed.
63PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")
65ARGUMENT_PERCENT_DEFAULT = PytestRemovedIn8Warning(
66 'pytest now uses argparse. "%default" should be changed to "%(default)s"',
67)
69ARGUMENT_TYPE_STR_CHOICE = UnformattedWarning(
70 PytestRemovedIn8Warning,
71 "`type` argument to addoption() is the string {typ!r}."
72 " For choices this is optional and can be omitted, "
73 " but when supplied should be a type (for example `str` or `int`)."
74 " (options: {names})",
75)
77ARGUMENT_TYPE_STR = UnformattedWarning(
78 PytestRemovedIn8Warning,
79 "`type` argument to addoption() is the string {typ!r}, "
80 " but when supplied should be a type (for example `str` or `int`)."
81 " (options: {names})",
82)
85HOOK_LEGACY_PATH_ARG = UnformattedWarning(
86 PytestRemovedIn8Warning,
87 "The ({pylib_path_arg}: py.path.local) argument is deprecated, please use ({pathlib_path_arg}: pathlib.Path)\n"
88 "see https://docs.pytest.org/en/latest/deprecations.html"
89 "#py-path-local-arguments-for-hooks-replaced-with-pathlib-path",
90)
92NODE_CTOR_FSPATH_ARG = UnformattedWarning(
93 PytestRemovedIn8Warning,
94 "The (fspath: py.path.local) argument to {node_type_name} is deprecated. "
95 "Please use the (path: pathlib.Path) argument instead.\n"
96 "See https://docs.pytest.org/en/latest/deprecations.html"
97 "#fspath-argument-for-node-constructors-replaced-with-pathlib-path",
98)
100WARNS_NONE_ARG = PytestRemovedIn8Warning(
101 "Passing None has been deprecated.\n"
102 "See https://docs.pytest.org/en/latest/how-to/capture-warnings.html"
103 "#additional-use-cases-of-warnings-in-tests"
104 " for alternatives in common use cases."
105)
107KEYWORD_MSG_ARG = UnformattedWarning(
108 PytestRemovedIn8Warning,
109 "pytest.{func}(msg=...) is now deprecated, use pytest.{func}(reason=...) instead",
110)
112INSTANCE_COLLECTOR = PytestRemovedIn8Warning(
113 "The pytest.Instance collector type is deprecated and is no longer used. "
114 "See https://docs.pytest.org/en/latest/deprecations.html#the-pytest-instance-collector",
115)
116HOOK_LEGACY_MARKING = UnformattedWarning(
117 PytestDeprecationWarning,
118 "The hook{type} {fullname} uses old-style configuration options (marks or attributes).\n"
119 "Please use the pytest.hook{type}({hook_opts}) decorator instead\n"
120 " to configure the hooks.\n"
121 " See https://docs.pytest.org/en/latest/deprecations.html"
122 "#configuring-hook-specs-impls-using-markers",
123)
125# You want to make some `__init__` or function "private".
126#
127# def my_private_function(some, args):
128# ...
129#
130# Do this:
131#
132# def my_private_function(some, args, *, _ispytest: bool = False):
133# check_ispytest(_ispytest)
134# ...
135#
136# Change all internal/allowed calls to
137#
138# my_private_function(some, args, _ispytest=True)
139#
140# All other calls will get the default _ispytest=False and trigger
141# the warning (possibly error in the future).
144def check_ispytest(ispytest: bool) -> None:
145 if not ispytest:
146 warn(PRIVATE, stacklevel=3)