You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user_guide.rst
+20-1Lines changed: 20 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -55,13 +55,31 @@ Environment
55
55
~~~~~~~~~~~
56
56
57
57
The *Environment* section is provided by the `pytest-metadata`_ plugin, and can be accessed
58
-
via the :code:`pytest_configure` hook:
58
+
via the :code:`pytest_configure` and :code:`pytest_sessionfinish` hooks:
59
+
60
+
To modify the *Environment* section **before** tests are run, use :code:`pytest_configure`:
59
61
60
62
.. code-block:: python
61
63
62
64
defpytest_configure(config):
63
65
config._metadata["foo"] ="bar"
64
66
67
+
To modify the *Environment* section **after** tests are run, use :code:`pytest_sessionfinish`:
68
+
69
+
.. code-block:: python
70
+
71
+
import pytest
72
+
73
+
74
+
@pytest.hookimpl(tryfirst=True)
75
+
defpytest_sessionfinish(session, exitstatus):
76
+
session.config._metadata["foo"] ="bar"
77
+
78
+
Note that in the above example `@pytest.hookimpl(tryfirst=True)`_ is important, as this ensures that a best effort attempt is made to run your
79
+
:code:`pytest_sessionfinish` **before** any other plugins ( including :code:`pytest-html` and :code:`pytest-metadata` ) run theirs.
80
+
If this line is omitted, then the *Environment* table will **not** be updated since the :code:`pytest_sessionfinish` of the plugins will execute first,
81
+
and thus not pick up your change.
82
+
65
83
The generated table will be sorted alphabetically unless the metadata is a
66
84
:code:`collections.OrderedDict`.
67
85
@@ -248,6 +266,7 @@ Below is an example of a :code:`conftest.py` file setting :code:`duration_format
248
266
249
267
**NOTE**: Milliseconds are always displayed with a precision of 2
0 commit comments