Skip to content

Commit 6d59143

Browse files
docs: clarify pytest_deselected/pytest_collection_modifyitems usage (#12729) (#12733)
Closes #12663 (cherry picked from commit 51845fc) Co-authored-by: Stefaan Lippens <[email protected]>
1 parent 8fb7fae commit 6d59143

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

changelog/12663.doc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify that the `pytest_deselected` hook should be called from `pytest_collection_modifyitems` hook implementations when items are deselected.

src/_pytest/hookspec.py

+11
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ def pytest_collection_modifyitems(
274274
"""Called after collection has been performed. May filter or re-order
275275
the items in-place.
276276
277+
When items are deselected (filtered out from ``items``),
278+
the hook :hook:`pytest_deselected` must be called explicitly
279+
with the deselected items to properly notify other plugins,
280+
e.g. with ``config.hook.pytest_deselected(deselected_items)``.
281+
277282
:param session: The pytest session object.
278283
:param config: The pytest config object.
279284
:param items: List of item objects.
@@ -454,6 +459,12 @@ def pytest_collectreport(report: CollectReport) -> None:
454459
def pytest_deselected(items: Sequence[Item]) -> None:
455460
"""Called for deselected test items, e.g. by keyword.
456461
462+
Note that this hook has two integration aspects for plugins:
463+
464+
- it can be *implemented* to be notified of deselected items
465+
- it must be *called* from :hook:`pytest_collection_modifyitems`
466+
implementations when items are deselected (to properly notify other plugins).
467+
457468
May be called multiple times.
458469
459470
:param items:

0 commit comments

Comments
 (0)