From 1fd14685c5860b248c51c9a39de3595ab62f45da Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 7 Apr 2020 08:08:28 +0200 Subject: [PATCH] doc: document inversed lines with terminal report hooks (#7016) It was surprising that `tryfirst=True` would not result in lines being added to the beginning with `pytest_report_header`. This is due to lines being reversed, and therefore the same applies to `pytest_report_collectionfinish`. --- doc/en/writing_plugins.rst | 1 + src/_pytest/hookspec.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/en/writing_plugins.rst b/doc/en/writing_plugins.rst index accda3634..87d81edb0 100644 --- a/doc/en/writing_plugins.rst +++ b/doc/en/writing_plugins.rst @@ -561,6 +561,7 @@ that result but it's probably better to avoid it. For more information, consult the :ref:`pluggy documentation about hookwrappers `. +.. _plugin-hookorder: Hook function ordering / call example ------------------------------------- diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 962ec8b3a..210cf2255 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -528,6 +528,13 @@ def pytest_report_header(config, startdir): :param _pytest.config.Config config: pytest config object :param startdir: py.path object with the starting dir + .. note:: + + Lines returned by a plugin are displayed before those of plugins which + ran before it. + If you want to have your line(s) displayed first, use + :ref:`trylast=True `. + .. note:: This function should be implemented only in plugins or ``conftest.py`` @@ -542,11 +549,18 @@ def pytest_report_collectionfinish(config, startdir, items): return a string or list of strings to be displayed after collection has finished successfully. - This strings will be displayed after the standard "collected X items" message. + These strings will be displayed after the standard "collected X items" message. :param _pytest.config.Config config: pytest config object :param startdir: py.path object with the starting dir :param items: list of pytest items that are going to be executed; this list should not be modified. + + .. note:: + + Lines returned by a plugin are displayed before those of plugins which + ran before it. + If you want to have your line(s) displayed first, use + :ref:`trylast=True `. """