Debian Codegraph @

doc/en/explanation/ci.rst

raw
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 pipelines. 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 is set to a non-empty value:
21
22 * :envvar:`CI`: used by many CI systems.
23 * :envvar:`BUILD_NUMBER`: used by Jenkins.
24
25 Effects on CI
26 -------------
27
28 For now, the effects on pytest of being in a CI environment are limited.
29
30 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.
31
32 .. code-block:: python
33
34 # content of test_ci.py
35 import pytest
36
37
38 def test_db_initialized():
39 pytest.fail(
40 "deliberately failing for demo purpose, Lorem ipsum dolor sit amet, "
41 "consectetur adipiscing elit. Cras facilisis, massa in suscipit "
42 "dignissim, mauris lacus molestie nisi, quis varius metus nulla ut ipsum."
43 )
44
45
46 Running this locally, without any extra options, will output:
47
48 .. code-block:: pytest
49
50 $ pytest test_ci.py
51 ...
52 ========================= short test summary info ==========================
53 FAILED test_ci.py::test_db_initialized - Failed: deliberately f...
54
55 *(Note the truncated text)*
56
57
58 While running this on CI will output:
59
60 .. code-block:: pytest
61
62 $ export CI=true
63 $ pytest test_ci.py
64 ...
65 ========================= short test summary info ==========================
66 FAILED test_ci.py::test_db_initialized - Failed: deliberately failing
67 for demo purpose, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras
68 facilisis, massa in suscipit dignissim, mauris lacus molestie nisi, quis varius
69 metus nulla ut ipsum.