|
| 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. |
0 commit comments