Skip to content

Commit d69abff

Browse files
authored
Merge pull request #7660 from nicoddemus/deprecated-features
2 parents c98525b + 372a094 commit d69abff

20 files changed

+105
-806
lines changed

changelog/5585.breaking.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
As per our policy, the following features have been deprecated in the 5.X series and are now
2+
removed:
3+
4+
* The ``funcargnames`` read-only property of ``FixtureRequest``, ``Metafunc``, and ``Function`` classes. Use ``fixturenames`` attribute.
5+
6+
* ``@pytest.fixture`` no longer supports positional arguments, pass all arguments by keyword instead.
7+
8+
* Direct construction of ``Node`` subclasses now raise an error, use ``from_parent`` instead.
9+
10+
* The default value for ``junit_family`` has changed to ``xunit2``. If you require the old format, add ``junit_family=xunit1`` to your configuration file.
11+
12+
* The ``TerminalReporter`` no longer has a ``writer`` attribute. Plugin authors may use the public functions of the ``TerminalReporter`` instead of accessing the ``TerminalWriter`` object directly.
13+
14+
* The ``--result-log`` option has been removed. Users are recommended to use the `pytest-reportlog <https://github.com/pytest-dev/pytest-reportlog>`__ plugin instead.
15+
16+
17+
For more information consult
18+
`Deprecations and Removals <https://docs.pytest.org/en/stable/deprecations.html>`__ in the docs.

doc/en/deprecations.rst

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``
3030
Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter
3131
by a ``nodeid`` parameter.
3232

33+
The ``pytest.collect`` module
34+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
36+
.. deprecated:: 6.0
37+
38+
The ``pytest.collect`` module is no longer part of the public API, all its names
39+
should now be imported from ``pytest`` directly instead.
40+
3341

3442
The ``pytest._fillfuncargs`` function
3543
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3644

37-
.. deprecated:: 5.5
45+
.. deprecated:: 6.0
3846

3947
This function was kept for backward compatibility with an older plugin.
4048

@@ -43,6 +51,11 @@ it, use `function._request._fillfixtures()` instead, though note this is not
4351
a public API and may break in the future.
4452

4553

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.
4659

4760
``--no-print-logs`` command-line option
4861
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -59,38 +72,46 @@ display captured output when tests fail: ``no``, ``stdout``, ``stderr``, ``log``
5972

6073

6174

62-
Node Construction changed to ``Node.from_parent``
63-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75+
Result log (``--result-log``)
76+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6477

65-
.. deprecated:: 5.4
78+
.. deprecated:: 4.0
79+
.. versionremoved:: 6.0
6680

67-
The construction of nodes now should use the named constructor ``from_parent``.
68-
This limitation in api surface intends to enable better/simpler refactoring of the collection tree.
81+
The ``--result-log`` option produces a stream of test reports which can be
82+
analysed at runtime, but it uses a custom format which requires users to implement their own
83+
parser.
6984

70-
This means that instead of :code:`MyItem(name="foo", parent=collector, obj=42)`
71-
one now has to invoke :code:`MyItem.from_parent(collector, name="foo")`.
85+
The `pytest-reportlog <https://github.com/pytest-dev/pytest-reportlog>`__ plugin provides a ``--report-log`` option, a more standard and extensible alternative, producing
86+
one JSON object per-line, and should cover the same use cases. Please try it out and provide feedback.
7287

73-
Plugins that wish to support older versions of pytest and suppress the warning can use
74-
`hasattr` to check if `from_parent` exists in that version:
88+
The ``pytest-reportlog`` plugin might even be merged into the core
89+
at some point, depending on the plans for the plugins and number of users using it.
7590

76-
.. code-block:: python
91+
``pytest_collect_directory`` hook
92+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7793

78-
def pytest_pycollect_makeitem(collector, name, obj):
79-
if hasattr(MyItem, "from_parent"):
80-
item = MyItem.from_parent(collector, name="foo")
81-
item.obj = 42
82-
return item
83-
else:
84-
return MyItem(name="foo", parent=collector, obj=42)
94+
.. versionremoved:: 6.0
8595

86-
Note that ``from_parent`` should only be called with keyword arguments for the parameters.
96+
The ``pytest_collect_directory`` has not worked properly for years (it was called
97+
but the results were ignored). Users may consider using :func:`pytest_collection_modifyitems <_pytest.hookspec.pytest_collection_modifyitems>` instead.
8798

99+
TerminalReporter.writer
100+
~~~~~~~~~~~~~~~~~~~~~~~
88101

102+
.. versionremoved:: 6.0
103+
104+
The ``TerminalReporter.writer`` attribute has been deprecated and should no longer be used. This
105+
was inadvertently exposed as part of the public API of that plugin and ties it too much
106+
with ``py.io.TerminalWriter``.
107+
108+
Plugins that used ``TerminalReporter.writer`` directly should instead use ``TerminalReporter``
109+
methods that provide the same functionality.
89110

90111
``junit_family`` default value change to "xunit2"
91112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92113

93-
.. deprecated:: 5.2
114+
.. versionchanged:: 6.0
94115

95116
The default value of ``junit_family`` option will change to ``xunit2`` in pytest 6.0, which
96117
is an update of the old ``xunit1`` format and is supported by default in modern tools
@@ -126,55 +147,52 @@ Services known to support the ``xunit2`` format:
126147
* `Jenkins <https://www.jenkins.io/>`__ with the `JUnit <https://plugins.jenkins.io/junit>`__ plugin.
127148
* `Azure Pipelines <https://azure.microsoft.com/en-us/services/devops/pipelines>`__.
128149

150+
Node Construction changed to ``Node.from_parent``
151+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129152

130-
``funcargnames`` alias for ``fixturenames``
131-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132-
133-
.. deprecated:: 5.0
134-
135-
The ``FixtureRequest``, ``Metafunc``, and ``Function`` classes track the names of
136-
their associated fixtures, with the aptly-named ``fixturenames`` attribute.
153+
.. versionchanged:: 6.0
137154

138-
Prior to pytest 2.3, this attribute was named ``funcargnames``, and we have kept
139-
that as an alias since. It is finally due for removal, as it is often confusing
140-
in places where we or plugin authors must distinguish between fixture names and
141-
names supplied by non-fixture things such as ``pytest.mark.parametrize``.
155+
The construction of nodes now should use the named constructor ``from_parent``.
156+
This limitation in api surface intends to enable better/simpler refactoring of the collection tree.
142157

158+
This means that instead of :code:`MyItem(name="foo", parent=collector, obj=42)`
159+
one now has to invoke :code:`MyItem.from_parent(collector, name="foo")`.
143160

144-
Result log (``--result-log``)
145-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
161+
Plugins that wish to support older versions of pytest and suppress the warning can use
162+
`hasattr` to check if `from_parent` exists in that version:
146163

147-
.. deprecated:: 4.0
164+
.. code-block:: python
148165
149-
The ``--result-log`` option produces a stream of test reports which can be
150-
analysed at runtime, but it uses a custom format which requires users to implement their own
151-
parser.
166+
def pytest_pycollect_makeitem(collector, name, obj):
167+
if hasattr(MyItem, "from_parent"):
168+
item = MyItem.from_parent(collector, name="foo")
169+
item.obj = 42
170+
return item
171+
else:
172+
return MyItem(name="foo", parent=collector, obj=42)
152173
153-
The `pytest-reportlog <https://github.com/pytest-dev/pytest-reportlog>`__ plugin provides a ``--report-log`` option, a more standard and extensible alternative, producing
154-
one JSON object per-line, and should cover the same use cases. Please try it out and provide feedback.
174+
Note that ``from_parent`` should only be called with keyword arguments for the parameters.
155175

156-
The plan is remove the ``--result-log`` option in pytest 6.0 if ``pytest-reportlog`` proves satisfactory
157-
to all users and is deemed stable. The ``pytest-reportlog`` plugin might even be merged into the core
158-
at some point, depending on the plans for the plugins and number of users using it.
159176

160-
TerminalReporter.writer
161-
~~~~~~~~~~~~~~~~~~~~~~~
177+
``pytest.fixture`` arguments are keyword only
178+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162179

163-
.. deprecated:: 5.4
180+
.. versionremoved:: 6.0
164181

165-
The ``TerminalReporter.writer`` attribute has been deprecated and should no longer be used. This
166-
was inadvertently exposed as part of the public API of that plugin and ties it too much
167-
with ``py.io.TerminalWriter``.
182+
Passing arguments to pytest.fixture() as positional arguments has been removed - pass them by keyword instead.
168183

169-
Plugins that used ``TerminalReporter.writer`` directly should instead use ``TerminalReporter``
170-
methods that provide the same functionality.
184+
``funcargnames`` alias for ``fixturenames``
185+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171186

187+
.. versionremoved:: 6.0
172188

173-
Removed Features
174-
----------------
189+
The ``FixtureRequest``, ``Metafunc``, and ``Function`` classes track the names of
190+
their associated fixtures, with the aptly-named ``fixturenames`` attribute.
175191

176-
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
177-
an appropriate period of deprecation has passed.
192+
Prior to pytest 2.3, this attribute was named ``funcargnames``, and we have kept
193+
that as an alias since. It is finally due for removal, as it is often confusing
194+
in places where we or plugin authors must distinguish between fixture names and
195+
names supplied by non-fixture things such as ``pytest.mark.parametrize``.
178196

179197

180198
``pytest.config`` global

doc/en/reference.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ Collection hooks
656656

657657
.. autofunction:: pytest_collection
658658
.. autofunction:: pytest_ignore_collect
659-
.. autofunction:: pytest_collect_directory
660659
.. autofunction:: pytest_collect_file
661660
.. autofunction:: pytest_pycollect_makemodule
662661

src/_pytest/config/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def directory_arg(path: str, optname: str) -> str:
239239
"nose",
240240
"assertion",
241241
"junitxml",
242-
"resultlog",
243242
"doctest",
244243
"cacheprovider",
245244
"freeze_support",

src/_pytest/deprecated.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,19 @@
1919
"pytest_faulthandler",
2020
}
2121

22-
FUNCARGNAMES = PytestDeprecationWarning(
23-
"The `funcargnames` attribute was an alias for `fixturenames`, "
24-
"since pytest 2.3 - use the newer attribute instead."
25-
)
2622

2723
FILLFUNCARGS = PytestDeprecationWarning(
2824
"The `_fillfuncargs` function is deprecated, use "
2925
"function._request._fillfixtures() instead if you cannot avoid reaching into internals."
3026
)
3127

32-
RESULT_LOG = PytestDeprecationWarning(
33-
"--result-log is deprecated, please try the new pytest-reportlog plugin.\n"
34-
"See https://docs.pytest.org/en/stable/deprecations.html#result-log-result-log for more information."
35-
)
36-
37-
FIXTURE_POSITIONAL_ARGUMENTS = PytestDeprecationWarning(
38-
"Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them "
39-
"as a keyword argument instead."
40-
)
41-
42-
NODE_USE_FROM_PARENT = UnformattedWarning(
43-
PytestDeprecationWarning,
44-
"Direct construction of {name} has been deprecated, please use {name}.from_parent.\n"
45-
"See "
46-
"https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent"
47-
" for more details.",
48-
)
49-
50-
JUNIT_XML_DEFAULT_FAMILY = PytestDeprecationWarning(
51-
"The 'junit_family' default value will change to 'xunit2' in pytest 6.0. See:\n"
52-
" https://docs.pytest.org/en/stable/deprecations.html#junit-family-default-value-change-to-xunit2\n"
53-
"for more information."
54-
)
55-
56-
COLLECT_DIRECTORY_HOOK = PytestDeprecationWarning(
57-
"The pytest_collect_directory hook is not working.\n"
58-
"Please use collect_ignore in conftests or pytest_collection_modifyitems."
59-
)
60-
6128
PYTEST_COLLECT_MODULE = UnformattedWarning(
6229
PytestDeprecationWarning,
6330
"pytest.collect.{name} was moved to pytest.{name}\n"
6431
"Please update to the new name.",
6532
)
6633

6734

68-
TERMINALWRITER_WRITER = PytestDeprecationWarning(
69-
"The TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\n"
70-
"See https://docs.pytest.org/en/stable/deprecations.html#terminalreporter-writer for more information."
71-
)
72-
73-
7435
MINUS_K_DASH = PytestDeprecationWarning(
7536
"The `-k '-expr'` syntax to -k is deprecated.\nUse `-k 'not expr'` instead."
7637
)

src/_pytest/fixtures.py

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import inspect
33
import os
44
import sys
5-
import warnings
65
from collections import defaultdict
76
from collections import deque
87
from types import TracebackType
@@ -46,8 +45,6 @@
4645
from _pytest.config import _PluggyPlugin
4746
from _pytest.config import Config
4847
from _pytest.config.argparsing import Parser
49-
from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS
50-
from _pytest.deprecated import FUNCARGNAMES
5148
from _pytest.mark import ParameterSet
5249
from _pytest.outcomes import fail
5350
from _pytest.outcomes import TEST_OUTCOME
@@ -457,12 +454,6 @@ def fixturenames(self) -> List[str]:
457454
result.extend(set(self._fixture_defs).difference(result))
458455
return result
459456

460-
@property
461-
def funcargnames(self) -> List[str]:
462-
"""Alias attribute for ``fixturenames`` for pre-2.3 compatibility."""
463-
warnings.warn(FUNCARGNAMES, stacklevel=2)
464-
return self.fixturenames
465-
466457
@property
467458
def node(self):
468459
"""Underlying collection node (depends on current request scope)."""
@@ -1253,7 +1244,7 @@ def fixture( # noqa: F811
12531244

12541245
def fixture( # noqa: F811
12551246
fixture_function: Optional[_FixtureFunction] = None,
1256-
*args: Any,
1247+
*,
12571248
scope: "Union[_Scope, Callable[[str, Config], _Scope]]" = "function",
12581249
params: Optional[Iterable[object]] = None,
12591250
autouse: bool = False,
@@ -1315,53 +1306,6 @@ def fixture( # noqa: F811
13151306
name the decorated function ``fixture_<fixturename>`` and then use
13161307
``@pytest.fixture(name='<fixturename>')``.
13171308
"""
1318-
# Positional arguments backward compatibility.
1319-
# If a kwarg is equal to its default, assume it was not explicitly
1320-
# passed, i.e. not duplicated. The more correct way is to use a
1321-
# **kwargs and check `in`, but that obfuscates the function signature.
1322-
if isinstance(fixture_function, str):
1323-
# It's actually the first positional argument, scope.
1324-
args = (fixture_function, *args) # type: ignore[unreachable]
1325-
fixture_function = None
1326-
duplicated_args = []
1327-
if len(args) > 0:
1328-
if scope == "function":
1329-
scope = args[0]
1330-
else:
1331-
duplicated_args.append("scope")
1332-
if len(args) > 1:
1333-
if params is None:
1334-
params = args[1]
1335-
else:
1336-
duplicated_args.append("params")
1337-
if len(args) > 2:
1338-
if autouse is False:
1339-
autouse = args[2]
1340-
else:
1341-
duplicated_args.append("autouse")
1342-
if len(args) > 3:
1343-
if ids is None:
1344-
ids = args[3]
1345-
else:
1346-
duplicated_args.append("ids")
1347-
if len(args) > 4:
1348-
if name is None:
1349-
name = args[4]
1350-
else:
1351-
duplicated_args.append("name")
1352-
if len(args) > 5:
1353-
raise TypeError(
1354-
"fixture() takes 5 positional arguments but {} were given".format(len(args))
1355-
)
1356-
if duplicated_args:
1357-
raise TypeError(
1358-
"The fixture arguments are defined as positional and keyword: {}. "
1359-
"Use only keyword arguments.".format(", ".join(duplicated_args))
1360-
)
1361-
if args:
1362-
warnings.warn(FIXTURE_POSITIONAL_ARGUMENTS, stacklevel=2)
1363-
# End backward compatiblity.
1364-
13651309
fixture_marker = FixtureFunctionMarker(
13661310
scope=scope, params=params, autouse=autouse, ids=ids, name=name,
13671311
)

src/_pytest/hookspec.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import py.path
1313
from pluggy import HookspecMarker
1414

15-
from .deprecated import COLLECT_DIRECTORY_HOOK
1615
from _pytest.compat import TYPE_CHECKING
1716

1817
if TYPE_CHECKING:
@@ -262,16 +261,6 @@ def pytest_ignore_collect(path: py.path.local, config: "Config") -> Optional[boo
262261
"""
263262

264263

265-
@hookspec(firstresult=True, warn_on_impl=COLLECT_DIRECTORY_HOOK)
266-
def pytest_collect_directory(path: py.path.local, parent) -> Optional[object]:
267-
"""Called before traversing a directory for collection files.
268-
269-
Stops at first non-None result, see :ref:`firstresult`.
270-
271-
:param py.path.local path: The path to analyze.
272-
"""
273-
274-
275264
def pytest_collect_file(path: py.path.local, parent) -> "Optional[Collector]":
276265
"""Return collection Node or None for the given path.
277266

0 commit comments

Comments
 (0)