Skip to content

Commit 3173815

Browse files
authored
Remove deprecated features (#5529)
Remove deprecated features
2 parents 39a43db + dfe54cd commit 3173815

31 files changed

+339
-645
lines changed

changelog/5180.removal.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
As per our policy, the following features have been deprecated in the 4.X series and are now
2+
removed:
3+
4+
* ``Request.getfuncargvalue``: use ``Request.getfixturevalue`` instead.
5+
6+
* ``pytest.raises`` and ``pytest.warns`` no longer support strings as the second argument.
7+
8+
* ``message`` parameter of ``pytest.raises``.
9+
10+
* ``pytest.raises``, ``pytest.warns`` and ``ParameterSet.param`` now use native keyword-only
11+
syntax. This might change the exception message from previous versions, but they still raise
12+
``TypeError`` on unknown keyword arguments as before.
13+
14+
* ``pytest.config`` global variable.
15+
16+
* ``tmpdir_factory.ensuretemp`` method.
17+
18+
* ``pytest_logwarning`` hook.
19+
20+
* ``RemovedInPytest4Warning`` warning type.
21+
22+
* ``request`` is now a reserved name for fixtures.
23+
24+
25+
For more information consult
26+
`Deprecations and Removals <https://docs.pytest.org/en/latest/deprecations.html>`__ in the docs.

doc/en/deprecations.rst

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Below is a complete list of all pytest features which are considered deprecated.
2020
:ref:`standard warning filters <warnings>`.
2121

2222

23-
Removal of ``funcargnames`` alias for ``fixturenames``
24-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
``funcargnames`` alias for ``fixturenames``
24+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2525

2626
.. deprecated:: 5.0
2727

@@ -34,12 +34,47 @@ in places where we or plugin authors must distinguish between fixture names and
3434
names supplied by non-fixture things such as ``pytest.mark.parametrize``.
3535

3636

37+
Result log (``--result-log``)
38+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39+
40+
.. deprecated:: 4.0
41+
42+
The ``--result-log`` option produces a stream of test reports which can be
43+
analysed at runtime. It uses a custom format which requires users to implement their own
44+
parser, but the team believes using a line-based format that can be parsed using standard
45+
tools would provide a suitable and better alternative.
46+
47+
The current plan is to provide an alternative in the pytest 5.0 series and remove the ``--result-log``
48+
option in pytest 6.0 after the new implementation proves satisfactory to all users and is deemed
49+
stable.
50+
51+
The actual alternative is still being discussed in issue `#4488 <https://github.com/pytest-dev/pytest/issues/4488>`__.
52+
53+
54+
Removed Features
55+
----------------
56+
57+
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
58+
an appropriate period of deprecation has passed.
59+
60+
61+
``pytest.config`` global
62+
~~~~~~~~~~~~~~~~~~~~~~~~
63+
64+
.. versionremoved:: 5.0
65+
66+
The ``pytest.config`` global object is deprecated. Instead use
67+
``request.config`` (via the ``request`` fixture) or if you are a plugin author
68+
use the ``pytest_configure(config)`` hook. Note that many hooks can also access
69+
the ``config`` object indirectly, through ``session.config`` or ``item.config`` for example.
70+
71+
3772
.. _`raises message deprecated`:
3873

3974
``"message"`` parameter of ``pytest.raises``
4075
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4176

42-
.. deprecated:: 4.1
77+
.. versionremoved:: 5.0
4378

4479
It is a common mistake to think this parameter will match the exception message, while in fact
4580
it only serves to provide a custom message in case the ``pytest.raises`` check fails. To prevent
@@ -70,22 +105,12 @@ If you still have concerns about this deprecation and future removal, please com
70105
`issue #3974 <https://github.com/pytest-dev/pytest/issues/3974>`__.
71106

72107

73-
``pytest.config`` global
74-
~~~~~~~~~~~~~~~~~~~~~~~~
75-
76-
.. deprecated:: 4.1
77-
78-
The ``pytest.config`` global object is deprecated. Instead use
79-
``request.config`` (via the ``request`` fixture) or if you are a plugin author
80-
use the ``pytest_configure(config)`` hook. Note that many hooks can also access
81-
the ``config`` object indirectly, through ``session.config`` or ``item.config`` for example.
82-
83108
.. _raises-warns-exec:
84109

85110
``raises`` / ``warns`` with a string as the second argument
86111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87112

88-
.. deprecated:: 4.1
113+
.. versionremoved:: 5.0
89114

90115
Use the context manager form of these instead. When necessary, invoke ``exec``
91116
directly.
@@ -116,27 +141,6 @@ Becomes:
116141
117142
118143
119-
Result log (``--result-log``)
120-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121-
122-
.. deprecated:: 4.0
123-
124-
The ``--result-log`` option produces a stream of test reports which can be
125-
analysed at runtime. It uses a custom format which requires users to implement their own
126-
parser, but the team believes using a line-based format that can be parsed using standard
127-
tools would provide a suitable and better alternative.
128-
129-
The current plan is to provide an alternative in the pytest 5.0 series and remove the ``--result-log``
130-
option in pytest 6.0 after the new implementation proves satisfactory to all users and is deemed
131-
stable.
132-
133-
The actual alternative is still being discussed in issue `#4488 <https://github.com/pytest-dev/pytest/issues/4488>`__.
134-
135-
Removed Features
136-
----------------
137-
138-
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
139-
an appropriate period of deprecation has passed.
140144
141145
Using ``Class`` in custom Collectors
142146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/en/warnings.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,3 @@ The following warning types ares used by pytest and are part of the public API:
430430
.. autoclass:: pytest.PytestUnhandledCoroutineWarning
431431

432432
.. autoclass:: pytest.PytestUnknownMarkWarning
433-
434-
.. autoclass:: pytest.RemovedInPytest4Warning

src/_pytest/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def iscoroutinefunction(func):
5656
)
5757

5858

59-
def getlocation(function, curdir):
59+
def getlocation(function, curdir=None):
6060
function = get_real_func(function)
6161
fn = py.path.local(inspect.getfile(function))
6262
lineno = function.__code__.co_firstlineno
63-
if fn.relto(curdir):
63+
if curdir is not None and fn.relto(curdir):
6464
fn = fn.relto(curdir)
6565
return "%s:%d" % (fn, lineno + 1)
6666

src/_pytest/config/__init__.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import _pytest._code
1919
import _pytest.assertion
20+
import _pytest.deprecated
2021
import _pytest.hookspec # the extension point definitions
2122
from .exceptions import PrintHelp
2223
from .exceptions import UsageError
@@ -204,6 +205,19 @@ def _prepareconfig(args=None, plugins=None):
204205
raise
205206

206207

208+
def _fail_on_non_top_pytest_plugins(conftestpath, confcutdir):
209+
msg = (
210+
"Defining 'pytest_plugins' in a non-top-level conftest is no longer supported:\n"
211+
"It affects the entire test suite instead of just below the conftest as expected.\n"
212+
" {}\n"
213+
"Please move it to a top level conftest file at the rootdir:\n"
214+
" {}\n"
215+
"For more information, visit:\n"
216+
" https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files"
217+
)
218+
fail(msg.format(conftestpath, confcutdir), pytrace=False)
219+
220+
207221
class PytestPluginManager(PluginManager):
208222
"""
209223
Overwrites :py:class:`pluggy.PluginManager <pluggy.PluginManager>` to add pytest-specific
@@ -424,16 +438,7 @@ def _importconftest(self, conftestpath):
424438
and self._configured
425439
and not self._using_pyargs
426440
):
427-
from _pytest.deprecated import (
428-
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST,
429-
)
430-
431-
fail(
432-
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST.format(
433-
conftestpath, self._confcutdir
434-
),
435-
pytrace=False,
436-
)
441+
_fail_on_non_top_pytest_plugins(conftestpath, self._confcutdir)
437442
except Exception:
438443
raise ConftestImportFailure(conftestpath, sys.exc_info())
439444

src/_pytest/config/findpaths.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ def getcfg(args, config=None):
2020
2121
note: config is optional and used only to issue warnings explicitly (#2891).
2222
"""
23-
from _pytest.deprecated import CFG_PYTEST_SECTION
24-
2523
inibasenames = ["pytest.ini", "tox.ini", "setup.cfg"]
2624
args = [x for x in args if not str(x).startswith("-")]
2725
if not args:
@@ -97,6 +95,9 @@ def get_dir_from_path(path):
9795
return [get_dir_from_path(path) for path in possible_paths if path.exists()]
9896

9997

98+
CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."
99+
100+
100101
def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None):
101102
dirs = get_dirs_from_args(args)
102103
if inifile:
@@ -107,8 +108,6 @@ def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None):
107108
try:
108109
inicfg = iniconfig[section]
109110
if is_cfg_file and section == "pytest" and config is not None:
110-
from _pytest.deprecated import CFG_PYTEST_SECTION
111-
112111
fail(
113112
CFG_PYTEST_SECTION.format(filename=str(inifile)), pytrace=False
114113
)

src/_pytest/deprecated.py

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
in case of warnings which need to format their messages.
1010
"""
1111
from _pytest.warning_types import PytestDeprecationWarning
12-
from _pytest.warning_types import RemovedInPytest4Warning
13-
from _pytest.warning_types import UnformattedWarning
14-
15-
YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
1612

1713
# set of plugins which have been integrated into the core; we use this list to ignore
1814
# them during registration to avoid conflicts
@@ -23,82 +19,13 @@
2319
}
2420

2521

26-
FIXTURE_FUNCTION_CALL = (
27-
'Fixture "{name}" called directly. Fixtures are not meant to be called directly,\n'
28-
"but are created automatically when test functions request them as parameters.\n"
29-
"See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and\n"
30-
"https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code."
31-
)
32-
33-
FIXTURE_NAMED_REQUEST = PytestDeprecationWarning(
34-
"'request' is a reserved name for fixtures and will raise an error in future versions"
35-
)
36-
37-
CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."
38-
39-
GETFUNCARGVALUE = RemovedInPytest4Warning(
40-
"getfuncargvalue is deprecated, use getfixturevalue"
41-
)
42-
4322
FUNCARGNAMES = PytestDeprecationWarning(
4423
"The `funcargnames` attribute was an alias for `fixturenames`, "
4524
"since pytest 2.3 - use the newer attribute instead."
4625
)
4726

48-
RAISES_MESSAGE_PARAMETER = PytestDeprecationWarning(
49-
"The 'message' parameter is deprecated.\n"
50-
"(did you mean to use `match='some regex'` to check the exception message?)\n"
51-
"Please see:\n"
52-
" https://docs.pytest.org/en/4.6-maintenance/deprecations.html#message-parameter-of-pytest-raises"
53-
)
5427

5528
RESULT_LOG = PytestDeprecationWarning(
5629
"--result-log is deprecated and scheduled for removal in pytest 6.0.\n"
5730
"See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information."
5831
)
59-
60-
RAISES_EXEC = PytestDeprecationWarning(
61-
"raises(..., 'code(as_a_string)') is deprecated, use the context manager form or use `exec()` directly\n\n"
62-
"See https://docs.pytest.org/en/latest/deprecations.html#raises-warns-exec"
63-
)
64-
WARNS_EXEC = PytestDeprecationWarning(
65-
"warns(..., 'code(as_a_string)') is deprecated, use the context manager form or use `exec()` directly.\n\n"
66-
"See https://docs.pytest.org/en/latest/deprecations.html#raises-warns-exec"
67-
)
68-
69-
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = (
70-
"Defining 'pytest_plugins' in a non-top-level conftest is no longer supported "
71-
"because it affects the entire directory tree in a non-explicit way.\n"
72-
" {}\n"
73-
"Please move it to a top level conftest file at the rootdir:\n"
74-
" {}\n"
75-
"For more information, visit:\n"
76-
" https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files"
77-
)
78-
79-
PYTEST_CONFIG_GLOBAL = PytestDeprecationWarning(
80-
"the `pytest.config` global is deprecated. Please use `request.config` "
81-
"or `pytest_configure` (if you're a pytest plugin) instead."
82-
)
83-
84-
PYTEST_ENSURETEMP = RemovedInPytest4Warning(
85-
"pytest/tmpdir_factory.ensuretemp is deprecated, \n"
86-
"please use the tmp_path fixture or tmp_path_factory.mktemp"
87-
)
88-
89-
PYTEST_LOGWARNING = PytestDeprecationWarning(
90-
"pytest_logwarning is deprecated, no longer being called, and will be removed soon\n"
91-
"please use pytest_warning_captured instead"
92-
)
93-
94-
PYTEST_WARNS_UNKNOWN_KWARGS = UnformattedWarning(
95-
PytestDeprecationWarning,
96-
"pytest.warns() got unexpected keyword arguments: {args!r}.\n"
97-
"This will be an error in future versions.",
98-
)
99-
100-
PYTEST_PARAM_UNKNOWN_KWARGS = UnformattedWarning(
101-
PytestDeprecationWarning,
102-
"pytest.param() got unexpected keyword arguments: {args!r}.\n"
103-
"This will be an error in future versions.",
104-
)

src/_pytest/fixtures.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import inspect
33
import itertools
44
import sys
5-
import warnings
65
from collections import defaultdict
76
from collections import deque
87
from collections import OrderedDict
@@ -28,8 +27,6 @@
2827
from _pytest.compat import is_generator
2928
from _pytest.compat import NOTSET
3029
from _pytest.compat import safe_getattr
31-
from _pytest.deprecated import FIXTURE_FUNCTION_CALL
32-
from _pytest.deprecated import FIXTURE_NAMED_REQUEST
3330
from _pytest.outcomes import fail
3431
from _pytest.outcomes import TEST_OUTCOME
3532

@@ -475,13 +472,6 @@ def getfixturevalue(self, argname):
475472
"""
476473
return self._get_active_fixturedef(argname).cached_result[0]
477474

478-
def getfuncargvalue(self, argname):
479-
""" Deprecated, use getfixturevalue. """
480-
from _pytest import deprecated
481-
482-
warnings.warn(deprecated.GETFUNCARGVALUE, stacklevel=2)
483-
return self.getfixturevalue(argname)
484-
485475
def _get_active_fixturedef(self, argname):
486476
try:
487477
return self._fixture_defs[argname]
@@ -945,9 +935,12 @@ def wrap_function_to_error_out_if_called_directly(function, fixture_marker):
945935
"""Wrap the given fixture function so we can raise an error about it being called directly,
946936
instead of used as an argument in a test function.
947937
"""
948-
message = FIXTURE_FUNCTION_CALL.format(
949-
name=fixture_marker.name or function.__name__
950-
)
938+
message = (
939+
'Fixture "{name}" called directly. Fixtures are not meant to be called directly,\n'
940+
"but are created automatically when test functions request them as parameters.\n"
941+
"See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and\n"
942+
"https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code."
943+
).format(name=fixture_marker.name or function.__name__)
951944

952945
@functools.wraps(function)
953946
def result(*args, **kwargs):
@@ -982,7 +975,13 @@ def __call__(self, function):
982975

983976
name = self.name or function.__name__
984977
if name == "request":
985-
warnings.warn(FIXTURE_NAMED_REQUEST)
978+
location = getlocation(function)
979+
fail(
980+
"'request' is a reserved word for fixtures, use another name:\n {}".format(
981+
location
982+
),
983+
pytrace=False,
984+
)
986985
function._pytestfixturefunction = self
987986
return function
988987

0 commit comments

Comments
 (0)