Skip to content

Commit

Permalink
docs: clarify pytest_deselected/pytest_collection_modifyitems usa…
Browse files Browse the repository at this point in the history
…ge (#12729)

Closes #12663
  • Loading branch information
soxofaan authored Aug 22, 2024
1 parent 33db65c commit 51845fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/12663.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify that the `pytest_deselected` hook should be called from `pytest_collection_modifyitems` hook implementations when items are deselected.
11 changes: 11 additions & 0 deletions src/_pytest/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ def pytest_collection_modifyitems(
"""Called after collection has been performed. May filter or re-order
the items in-place.
When items are deselected (filtered out from ``items``),
the hook :hook:`pytest_deselected` must be called explicitly
with the deselected items to properly notify other plugins,
e.g. with ``config.hook.pytest_deselected(deselected_items)``.
:param session: The pytest session object.
:param config: The pytest config object.
:param items: List of item objects.
Expand Down Expand Up @@ -454,6 +459,12 @@ def pytest_collectreport(report: CollectReport) -> None:
def pytest_deselected(items: Sequence[Item]) -> None:
"""Called for deselected test items, e.g. by keyword.
Note that this hook has two integration aspects for plugins:
- it can be *implemented* to be notified of deselected items
- it must be *called* from :hook:`pytest_collection_modifyitems`
implementations when items are deselected (to properly notify other plugins).
May be called multiple times.
:param items:
Expand Down

0 comments on commit 51845fc

Please sign in to comment.