This commit is contained in:
Daniel Hahler 2020-04-09 01:57:46 +02:00
parent 354602abe6
commit a98a62723e
1 changed files with 9 additions and 15 deletions

View File

@ -170,15 +170,11 @@ def pytest_load_initial_conftests(early_config, parser, args):
def pytest_collection(session: "Session") -> Optional[Any]: def pytest_collection(session: "Session") -> Optional[Any]:
"""Perform the collection protocol for the given session. """Perform the collection protocol for the given session.
Usually plugins will implement this hook only to perform some action before Stops at first non-None result, see :ref:`firstresult`.
collection, for example the terminal plugin will use this to start displaying The return value is not used, but only stops further processing.
the collection counter, so usually plugins return `None` from this hook after
performing the desired operation.
However a plugin might decide to override the collection completely, The hook is meant to set `session.items` to a sequence of items at least,
in which case it should return `True`, but then it is usually expected but normally should follow this procedure:
that this hook will also need to perform the following operations
that are usually part of the collection process:
1. Call the pytest_collectstart hook. 1. Call the pytest_collectstart hook.
2. Call the pytest_collectreport hook. 2. Call the pytest_collectreport hook.
@ -187,11 +183,9 @@ def pytest_collection(session: "Session") -> Optional[Any]:
5. Set session.testscollected to the amount of collect items. 5. Set session.testscollected to the amount of collect items.
6. Set `session.items` to a list of items. 6. Set `session.items` to a list of items.
If a plugin just wants to skip collection entirely, like `pytest-xdist` You can implement this hook to only perform some action before collection,
does for master nodes, then it is OK to not do anything other than for example the terminal plugin uses it to start displaying the collection
returning `True` from here. counter (and returns `None`).
Stops at first non-None result, see :ref:`firstresult`.
:param _pytest.main.Session session: the pytest session object :param _pytest.main.Session session: the pytest session object
""" """