diff --git a/src/_pytest/assertion/truncate.py b/src/_pytest/assertion/truncate.py index fb2377db3d3..7a03ab74136 100644 --- a/src/_pytest/assertion/truncate.py +++ b/src/_pytest/assertion/truncate.py @@ -4,7 +4,8 @@ Current default behaviour is to truncate assertion explanations at ~8 terminal lines, unless running in "-vv" mode or running on CI. """ -import os +from _pytest.assertion.util import _running_on_ci + DEFAULT_MAX_LINES = 8 DEFAULT_MAX_CHARS = 8 * 80 @@ -31,12 +32,6 @@ def _should_truncate_item(item): return int(level) > verbose -def _running_on_ci(): - """Check if we're currently running on a CI system.""" - env_vars = ["CI", "BUILD_NUMBER"] - return any(var in os.environ for var in env_vars) - - def _truncate_explanation(input_lines, max_lines=None, max_chars=None): """ Truncate given list of strings that makes up the assertion explanation. diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index 7521c08e4e4..27e3cb20ffa 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -1,5 +1,6 @@ """Utilities for assertion debugging""" import collections.abc +import os import pprint from typing import AbstractSet from typing import Any @@ -461,3 +462,7 @@ def _notin_text(term: str, text: str, verbose: int = 0) -> List[str]: else: newdiff.append(line) return newdiff + + +def _running_on_ci(): + return os.environ.get("CI") == "true" or "BUILD_NUMBER" in os.environ diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index a4e4ea1ba05..f1819d904a3 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -26,6 +26,7 @@ import pytest from _pytest import nodes +from _pytest.assertion.util import _running_on_ci from _pytest.compat import shell_quote from _pytest.main import ExitCode @@ -1048,8 +1049,7 @@ def short_test_summary(self) -> None: if not self.reportchars: return - # NOTE: there's also _pytest.assertion._running_on_ci. - if os.environ.get("CI") == "true" or not self.isatty: + if not self.isatty or _running_on_ci(): termwidth = None else: termwidth = self._tw.fullwidth diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 47d1ddafd9c..52284159e82 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -999,7 +999,13 @@ def test_many_lines(): result = testdir.runpytest("-vv") result.stdout.fnmatch_lines(["* 6*"]) - monkeypatch.setenv("CI", "1") + monkeypatch.setenv("CI", "") + result = testdir.runpytest() + result.stdout.fnmatch_lines( + ["E ...Full output truncated (2 lines hidden), use '-vv' to show"] + ) + + monkeypatch.setenv("CI", "true") result = testdir.runpytest() result.stdout.fnmatch_lines(["* 6*"])