File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,19 @@ This limitation in api surface intends to enable better/simpler refactoring of t
45
45
This means that instead of :code: `MyItem(name="foo", parent=collector, obj=42) `
46
46
one now has to invoke :code: `MyItem.from_parent(collector, name="foo") `.
47
47
48
+ Plugins that wish to support older versions of pytest and suppress the warning can use
49
+ `hasattr ` to check if `from_parent ` exists in that version:
50
+
51
+ .. code-block :: python
52
+
53
+ def pytest_pycollect_makeitem (collector , name , obj ):
54
+ if hasattr (MyItem, " from_parent" ):
55
+ item = MyItem.from_parent(collector, name = " foo" )
56
+ item.obj = 42
57
+ return item
58
+ else :
59
+ return MyItem(name = " foo" , parent = collector, obj = 42 )
60
+
48
61
Note that ``from_parent `` should only be called with keyword arguments for the parameters.
49
62
50
63
You can’t perform that action at this time.
0 commit comments