Skip to content

Commit 6933bef

Browse files
New docs about CI/BUILD_NUMBER env vars (#12578)
Closes #12577 Co-authored-by: Marc Bresson <[email protected]> Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 82e4071 commit 6933bef

File tree

5 files changed

+183
-102
lines changed

5 files changed

+183
-102
lines changed

changelog/12577.doc.rst

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`CI` and `BUILD_NUMBER` environment variables role is discribed in
2+
the reference doc. They now also appears when doing `pytest -h`
3+
-- by :user:`MarcBresson`.

doc/en/explanation/ci.rst

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. _`ci-pipelines`:
2+
3+
CI Pipelines
4+
============
5+
6+
Rationale
7+
---------
8+
9+
The goal of testing in a CI pipeline is different from testing locally. Indeed,
10+
you can quickly edit some code and run your tests again on your computer, but
11+
it is not possible with CI pipeline. They run on a separate server and are
12+
triggered by specific actions.
13+
14+
From that observation, pytest can detect when it is in a CI environment and
15+
adapt some of its behaviours.
16+
17+
How CI is detected
18+
------------------
19+
20+
Pytest knows it is in a CI environment when either one of these environment variables are set,
21+
regardless of their value:
22+
23+
* `CI`: used by many CI systems.
24+
* `BUILD_NUMBER`: used by Jenkins.
25+
26+
Effects on CI
27+
-------------
28+
29+
For now, the effects on pytest of being in a CI environment are limited.
30+
31+
When a CI environment is detected, the output of the short test summary info is no longer truncated to the terminal size i.e. the entire message will be shown.
32+
33+
.. code-block:: python
34+
35+
# content of test_ci.py
36+
import pytest
37+
38+
39+
def test_db_initialized():
40+
pytest.fail(
41+
"deliberately failing for demo purpose, Lorem ipsum dolor sit amet, "
42+
"consectetur adipiscing elit. Cras facilisis, massa in suscipit "
43+
"dignissim, mauris lacus molestie nisi, quis varius metus nulla ut ipsum."
44+
)
45+
46+
47+
Running this locally, without any extra options, will output:
48+
49+
.. code-block:: pytest
50+
51+
$ pytest test_ci.py
52+
...
53+
========================= short test summary info ==========================
54+
FAILED test_backends.py::test_db_initialized[d2] - Failed: deliberately f...
55+
56+
*(Note the truncated text)*
57+
58+
59+
While running this on CI will output:
60+
61+
.. code-block:: pytest
62+
63+
$ export CI=true
64+
$ pytest test_ci.py
65+
...
66+
========================= short test summary info ==========================
67+
FAILED test_backends.py::test_db_initialized[d2] - Failed: deliberately failing
68+
for demo purpose, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras
69+
facilisis, massa in suscipit dignissim, mauris lacus molestie nisi, quis varius
70+
metus nulla ut ipsum.

doc/en/explanation/index.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ Explanation
1111
anatomy
1212
fixtures
1313
goodpractices
14-
flaky
1514
pythonpath
15+
ci
16+
flaky

0 commit comments

Comments
 (0)