Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ coverage.xml
.vscode
__pycache__/
.python-version
.claude/settings.local.json

# generated by pip
pip-wheel-metadata/
Expand Down
1 change: 1 addition & 0 deletions changelog/14088.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarified that the default :hook:`pytest_collection` hook sets ``session.items`` before it calls :hook:`pytest_collection_finish`, not after.
1 change: 1 addition & 0 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ items, delete or otherwise amend the test items:
If this hook is implemented in ``conftest.py`` files, it always receives all collected items, not only those
under the ``conftest.py`` where it is implemented.

.. hook:: pytest_collection_finish
.. autofunction:: pytest_collection_finish

Test running (runtest) hooks
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ def pytest_collection(session: Session) -> object | None:

1. ``pytest_deselected(items)`` for any deselected items (may be called multiple times)

3. ``pytest_collection_finish(session)``
4. Set ``session.items`` to the list of collected items
3. Set ``session.items`` to the list of collected items
4. ``pytest_collection_finish(session)``
5. Set ``session.testscollected`` to the number of collected items

You can implement this hook to only perform some action before collection,
Expand Down