pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.9k stars 2.65k forks source link

Docs: collection hooks listed under reporting hooks #12658

Open soxofaan opened 1 month ago

soxofaan commented 1 month ago

In the docs, under "reporting hooks" I see a couple of hooks that I would expect under "collection hooks":

https://github.com/pytest-dev/pytest/blob/6c806b499ddbb844753b5c8c4d70a8b98b9d1c3a/doc/en/reference/reference.rst?plain=1#L759-L773

is that intended for some reason?

soxofaan commented 1 month ago

And while looking at it, some more hooks that look out of place in this section:

Maybe they better fit under "Test running (runtest) hooks"?

nicoddemus commented 1 month ago

Hi,

is that intended for some reason?

The rationale is that those hooks "report" events (item collected, header, test status, etc), while the "collection" hooks actually perform the collection itself.

And while looking at it, some more hooks that look out of place in this section:

You are right, pytest_fixture_setup and pytest_fixture_post_finalizer do seem like they belong in "Test running (runtest) hooks", but I would keep pytest_runtest_logreport there as it is about reporting the status of a test.

soxofaan commented 1 month ago

The rationale is that those hooks "report" events (item collected, header, test status, etc), while the "collection" hooks actually perform the collection itself.

Ok thanks for the quick response, that clarifies the current state. Still, if pytest_collectstart is a for reporting a start event, isn't that also true for pytest_sessionstart and pytest_runtest_logstart?

I guess a hook has multiple aspects which can be used for categorizing: what phase of the test suite are they about (collection, running, reporting), what scope do they have (session, fixture, node, report), are they about manipulating inputs or outcomes or just simple reporting, ... That easily leads to mismatching mental models of course :smile:

Another subtlety that might play here: if you talk about "reporting": is that about pytest reporting an event to a plugin, or about giving plugins the opportunity to report outcomes to the user?

nicoddemus commented 1 month ago

Another subtlety that might play here: if you talk about "reporting": is that about pytest reporting an event to a plugin, or about giving plugins the opportunity to report outcomes to the user?

Usually it is in the pytest -> plugin direction, and the plugin decides what to do with it.