Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Jon Parise
Jon Sonesen
Jonas Obrist
Jordan Guymon
Jordan Macdonald
Jordan Moldow
Jordan Speicher
Joseph Hunkeler
Expand Down
2 changes: 2 additions & 0 deletions changelog/13766.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Previously, pytest would assume it was running in a CI/CD environment if either of the environment variables `$CI` or `$BUILD_NUMBER` was defined;
now, CI mode is only activated if at least one of those variables is defined and set to a *non-empty* value.
3 changes: 1 addition & 2 deletions doc/en/explanation/ci.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ adapt some of its behaviours.
How CI is detected
------------------

Pytest knows it is in a CI environment when either one of these environment variables are set,
regardless of their value:
Pytest knows it is in a CI environment when either one of these environment variables are set to a non-empty value:

* `CI`: used by many CI systems.
* `BUILD_NUMBER`: used by Jenkins.
Expand Down
6 changes: 3 additions & 3 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1165,11 +1165,11 @@ Environment variables that can be used to change pytest's behavior.

.. envvar:: CI

When set (regardless of value), pytest acknowledges that is running in a CI process. Alternative to ``BUILD_NUMBER`` variable. See also :ref:`ci-pipelines`.
When set to a non-empty value, pytest acknowledges that is running in a CI process. See also :ref:`ci-pipelines`.

.. envvar:: BUILD_NUMBER

When set (regardless of value), pytest acknowledges that is running in a CI process. Alternative to CI variable. See also :ref:`ci-pipelines`.
When set to a non-empty value, pytest acknowledges that is running in a CI process. Alternative to :envvar:`CI`. See also :ref:`ci-pipelines`.

.. envvar:: PYTEST_ADDOPTS

Expand Down Expand Up @@ -2408,7 +2408,7 @@ All the command-line flags can be obtained by running ``pytest --help``::
Plugins that must be present for pytest to run

Environment variables:
CI When set (regardless of value), pytest knows it is running in a CI process and does not truncate summary info
CI When set to a non-empty value, pytest knows it is running in a CI process and does not truncate summary info
BUILD_NUMBER Equivalent to CI
PYTEST_ADDOPTS Extra command line options
PYTEST_PLUGINS Comma-separated plugins to load during startup
Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,6 @@ def __call__(self) -> bool:

def running_on_ci() -> bool:
"""Check if we're currently running on a CI system."""
# Only enable CI mode if one of these env variables is defined and non-empty.
env_vars = ["CI", "BUILD_NUMBER"]
return any(var in os.environ for var in env_vars)
return any(os.environ.get(var) for var in env_vars)
2 changes: 1 addition & 1 deletion src/_pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def showhelp(config: Config) -> None:
vars = [
(
"CI",
"When set (regardless of value), pytest knows it is running in a "
"When set to a non-empty value, pytest knows it is running in a "
"CI process and does not truncate summary info",
),
("BUILD_NUMBER", "Equivalent to CI"),
Expand Down
16 changes: 16 additions & 0 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ def test_full_diff():
result = pytester.runpytest()
result.stdout.fnmatch_lines(["E Full diff:"])

# Setting CI to empty string is same as having it undefined
monkeypatch.setenv("CI", "")
result = pytester.runpytest()
result.stdout.fnmatch_lines(["E Use -v to get more diff"])

monkeypatch.delenv("CI", raising=False)
result = pytester.runpytest()
result.stdout.fnmatch_lines(["E Use -v to get more diff"])
Expand Down Expand Up @@ -1465,6 +1470,17 @@ def test_many_lines():
result = pytester.runpytest("-vv")
result.stdout.fnmatch_lines(["* 6*"])

# Setting CI to empty string is same as having it undefined
monkeypatch.setenv("CI", "")
result = pytester.runpytest()
result.stdout.fnmatch_lines(
[
"*+ 1*",
"*+ 3*",
f"*truncated ({expected_truncated_lines} lines hidden)*use*-vv*",
]
)

monkeypatch.setenv("CI", "1")
result = pytester.runpytest()
result.stdout.fnmatch_lines(["* 6*"])
Expand Down
2 changes: 1 addition & 1 deletion testing/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_disabled():
pytest.param(
True,
marks=pytest.mark.skipif(
"CI" in os.environ
bool(os.environ.get("CI"))
and sys.platform == "linux"
and sys.version_info >= (3, 14),
reason="sometimes crashes on CI because of truncated outputs (#7022)",
Expand Down
Loading