Skip to content

Commit 0e9db5f

Browse files
authored
Clarify pytest_collection_finish occurs after setting session.items (#14088)
1 parent 33d5a09 commit 0e9db5f

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ coverage.xml
5151
.vscode
5252
__pycache__/
5353
.python-version
54+
.claude/settings.local.json
5455

5556
# generated by pip
5657
pip-wheel-metadata/

changelog/14088.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarified that the default :hook:`pytest_collection` hook sets ``session.items`` before it calls :hook:`pytest_collection_finish`, not after.

doc/en/reference/reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ items, delete or otherwise amend the test items:
757757
If this hook is implemented in ``conftest.py`` files, it always receives all collected items, not only those
758758
under the ``conftest.py`` where it is implemented.
759759

760+
.. hook:: pytest_collection_finish
760761
.. autofunction:: pytest_collection_finish
761762

762763
Test running (runtest) hooks

src/_pytest/hookspec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ def pytest_collection(session: Session) -> object | None:
248248
249249
1. ``pytest_deselected(items)`` for any deselected items (may be called multiple times)
250250
251-
3. ``pytest_collection_finish(session)``
252-
4. Set ``session.items`` to the list of collected items
251+
3. Set ``session.items`` to the list of collected items
252+
4. ``pytest_collection_finish(session)``
253253
5. Set ``session.testscollected`` to the number of collected items
254254
255255
You can implement this hook to only perform some action before collection,

0 commit comments

Comments
 (0)