Skip to content

Commit

Permalink
refactor ci helper to prepare for re-use
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszotten committed Aug 19, 2021
1 parent 16077f2 commit 2367e6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/_pytest/assertion/truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Current default behaviour is to truncate assertion explanations at
~8 terminal lines, unless running in "-vv" mode or running on CI.
"""
import os
from typing import List
from typing import Optional

from _pytest.assertion import util
from _pytest.nodes import Item


Expand All @@ -27,13 +27,7 @@ def truncate_if_required(
def _should_truncate_item(item: Item) -> bool:
"""Whether or not this test item is eligible for truncation."""
verbose = item.config.option.verbose
return verbose < 2 and not _running_on_ci()


def _running_on_ci() -> bool:
"""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)
return verbose < 2 and not util.running_on_ci()


def _truncate_explanation(
Expand Down
8 changes: 7 additions & 1 deletion 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 All @@ -17,7 +18,6 @@
from _pytest._io.saferepr import saferepr
from _pytest.config import Config


# The _reprcompare attribute on the util module is used by the new assertion
# interpretation code and assertion rewriter to detect this plugin was
# loaded and in turn call the hooks defined here as part of the
Expand Down Expand Up @@ -490,3 +490,9 @@ def _notin_text(term: str, text: str, verbose: int = 0) -> List[str]:
else:
newdiff.append(line)
return newdiff


def running_on_ci() -> bool:
"""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)

0 comments on commit 2367e6e

Please sign in to comment.