Skip to content

Commit 5c2f38f

Browse files
authored
Factor out/move _running_on_ci (#94)
Checks for `CI=true` explicitly, not just `"CI" in env`.
1 parent 0c0c1c5 commit 5c2f38f

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/_pytest/assertion/truncate.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Current default behaviour is to truncate assertion explanations at
55
~8 terminal lines, unless running in "-vv" mode or running on CI.
66
"""
7-
import os
7+
from _pytest.assertion.util import _running_on_ci
8+
89

910
DEFAULT_MAX_LINES = 8
1011
DEFAULT_MAX_CHARS = 8 * 80
@@ -31,12 +32,6 @@ def _should_truncate_item(item):
3132
return int(level) > verbose
3233

3334

34-
def _running_on_ci():
35-
"""Check if we're currently running on a CI system."""
36-
env_vars = ["CI", "BUILD_NUMBER"]
37-
return any(var in os.environ for var in env_vars)
38-
39-
4035
def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
4136
"""
4237
Truncate given list of strings that makes up the assertion explanation.

src/_pytest/assertion/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Utilities for assertion debugging"""
22
import collections.abc
3+
import os
34
import pprint
45
from typing import AbstractSet
56
from typing import Any
@@ -461,3 +462,7 @@ def _notin_text(term: str, text: str, verbose: int = 0) -> List[str]:
461462
else:
462463
newdiff.append(line)
463464
return newdiff
465+
466+
467+
def _running_on_ci():
468+
return os.environ.get("CI") == "true" or "BUILD_NUMBER" in os.environ

src/_pytest/terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import pytest
2828
from _pytest import nodes
29+
from _pytest.assertion.util import _running_on_ci
2930
from _pytest.compat import shell_quote
3031
from _pytest.main import ExitCode
3132

@@ -1048,8 +1049,7 @@ def short_test_summary(self) -> None:
10481049
if not self.reportchars:
10491050
return
10501051

1051-
# NOTE: there's also _pytest.assertion._running_on_ci.
1052-
if os.environ.get("CI") == "true" or not self.isatty:
1052+
if not self.isatty or _running_on_ci():
10531053
termwidth = None
10541054
else:
10551055
termwidth = self._tw.fullwidth

testing/test_assertion.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,13 @@ def test_many_lines():
999999
result = testdir.runpytest("-vv")
10001000
result.stdout.fnmatch_lines(["* 6*"])
10011001

1002-
monkeypatch.setenv("CI", "1")
1002+
monkeypatch.setenv("CI", "")
1003+
result = testdir.runpytest()
1004+
result.stdout.fnmatch_lines(
1005+
["E ...Full output truncated (2 lines hidden), use '-vv' to show"]
1006+
)
1007+
1008+
monkeypatch.setenv("CI", "true")
10031009
result = testdir.runpytest()
10041010
result.stdout.fnmatch_lines(["* 6*"])
10051011

0 commit comments

Comments
 (0)