@@ -56,6 +56,10 @@ Plugins which implement custom items and collectors are encouraged to replace
56
56
``fspath `` parameters (``py.path.local ``) with ``path `` parameters
57
57
(``pathlib.Path ``), and drop any other usage of the ``py `` library if possible.
58
58
59
+ If possible, plugins with custom items should use :ref: `cooperative
60
+ constructors <uncooperative-constructors-deprecated>` to avoid hardcoding
61
+ arguments they only pass on to the superclass.
62
+
59
63
.. note ::
60
64
The name of the :class: `~_pytest.nodes.Node ` arguments and attributes (the
61
65
new attribute being ``path ``) is **the opposite ** of the situation for
@@ -191,6 +195,40 @@ Instead, a separate collector node should be used, which collects the item. See
191
195
.. _example pr fixing inheritance : https://github.com/asmeurer/pytest-flakes/pull/40/files
192
196
193
197
198
+ .. _uncooperative-constructors-deprecated :
199
+
200
+ Constructors of custom :class: `pytest.Node ` subclasses should take ``**kwargs ``
201
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
202
+
203
+ .. deprecated :: 7.0
204
+
205
+ If custom subclasses of nodes like :class: `pytest.Item ` override the
206
+ ``__init__ `` method, they should take ``**kwargs ``. Thus,
207
+
208
+ .. code-block :: python
209
+
210
+ class CustomItem (pytest .Item ):
211
+ def __init__ (self , name , parent , additional_arg ):
212
+ super ().__init__ (name, parent)
213
+ self .additional_arg = additional_arg
214
+
215
+ should be turned into:
216
+
217
+ .. code-block :: python
218
+
219
+ class CustomItem (pytest .Item ):
220
+ def __init__ (self , * , additional_arg , ** kwargs ):
221
+ super ().__init__ (** kwargs)
222
+ self .additional_arg = additional_arg
223
+
224
+ to avoid hard-coding the arguments pytest can pass to the superclass.
225
+ See :ref: `non-python tests ` for a full example.
226
+
227
+ For cases without conflicts, no deprecation warning is emitted. For cases with
228
+ conflicts (such as :class: `pytest.File ` now taking ``path `` instead of
229
+ ``fspath ``, as :ref: `outlined above <node-ctor-fspath-deprecation >`), a
230
+ deprecation warning is now raised.
231
+
194
232
Backward compatibilities in ``Parser.addoption ``
195
233
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196
234
0 commit comments