Skip to content

Commit

Permalink
Factor out/move _running_on_ci (#94)
Browse files Browse the repository at this point in the history
Checks for `CI=true` explicitly, not just `"CI" in env`.
  • Loading branch information
blueyed authored Nov 7, 2019
1 parent 0c0c1c5 commit 5c2f38f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
9 changes: 2 additions & 7 deletions src/_pytest/assertion/truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/_pytest/assertion/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utilities for assertion debugging"""
import collections.abc
import os
import pprint
from typing import AbstractSet
from typing import Any
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*"])

Expand Down

0 comments on commit 5c2f38f

Please sign in to comment.