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
4 changes: 2 additions & 2 deletions src/_pytest/assertion/truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from __future__ import annotations

from _pytest.assertion import util
from _pytest.compat import running_on_ci
from _pytest.config import Config
from _pytest.nodes import Item

Expand Down Expand Up @@ -43,7 +43,7 @@ def _get_truncation_parameters(item: Item) -> tuple[bool, int, int]:

verbose = item.config.get_verbosity(Config.VERBOSITY_ASSERTIONS)

should_truncate = verbose < 2 and not util.running_on_ci()
should_truncate = verbose < 2 and not running_on_ci()
should_truncate = should_truncate and (max_lines > 0 or max_chars > 0)

return should_truncate, max_lines, max_chars
Expand Down
8 changes: 1 addition & 7 deletions src/_pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from collections.abc import Mapping
from collections.abc import Sequence
from collections.abc import Set as AbstractSet
import os
import pprint
from typing import Any
from typing import Literal
Expand All @@ -21,6 +20,7 @@
from _pytest._io.pprint import PrettyPrinter
from _pytest._io.saferepr import saferepr
from _pytest._io.saferepr import saferepr_unlimited
from _pytest.compat import running_on_ci
from _pytest.config import Config


Expand Down Expand Up @@ -613,9 +613,3 @@ 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)
Comment on lines -616 to -621
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this is helping for my current refactor on #13762 a lot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly my thinking :)

Empty file modified src/_pytest/cacheprovider.py
100755 → 100644
Empty file.
47 changes: 13 additions & 34 deletions src/_pytest/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: allow-untyped-defs
"""Python version compatibility code."""
"""Python version compatibility code and random general utilities."""

from __future__ import annotations

Expand Down Expand Up @@ -278,39 +278,12 @@ def get_user_id() -> int | None:
return uid if uid != ERROR else None


# Perform exhaustiveness checking.
#
# Consider this example:
#
# MyUnion = Union[int, str]
#
# def handle(x: MyUnion) -> int {
# if isinstance(x, int):
# return 1
# elif isinstance(x, str):
# return 2
# else:
# raise Exception('unreachable')
#
# Now suppose we add a new variant:
#
# MyUnion = Union[int, str, bytes]
#
# After doing this, we must remember ourselves to go and update the handle
# function to handle the new variant.
#
# With `assert_never` we can do better:
#
# // raise Exception('unreachable')
# return assert_never(x)
#
# Now, if we forget to handle the new variant, the type-checker will emit a
# compile-time error, instead of the runtime error we would have gotten
# previously.
#
# This also work for Enums (if you use `is` to compare) and Literals.
def assert_never(value: NoReturn) -> NoReturn:
assert False, f"Unhandled value: {value} ({type(value).__name__})"
if sys.version_info >= (3, 11):
from typing import assert_never
else:

def assert_never(value: NoReturn) -> NoReturn:
assert False, f"Unhandled value: {value} ({type(value).__name__})"


class CallableBool:
Expand All @@ -331,3 +304,9 @@ def __bool__(self) -> bool:

def __call__(self) -> bool:
return self._value


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)
2 changes: 1 addition & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from _pytest._io import TerminalWriter
from _pytest._io.wcwidth import wcswidth
import _pytest._version
from _pytest.assertion.util import running_on_ci
from _pytest.compat import running_on_ci
from _pytest.config import _PluggyPlugin
from _pytest.config import Config
from _pytest.config import ExitCode
Expand Down
2 changes: 1 addition & 1 deletion testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import tempfile
import textwrap

from _pytest.assertion.util import running_on_ci
from _pytest.compat import running_on_ci
from _pytest.config import ExitCode
from _pytest.fixtures import FixtureRequest
from _pytest.main import _in_venv
Expand Down