From d58b8380810aaf6aca61711ece95ce82ac9df056 Mon Sep 17 00:00:00 2001 From: Yijia-Xiao Date: Mon, 7 Sep 2026 21:28:52 +0000 Subject: [PATCH] test: keep the Ollama endpoint assertions off the terminal colour - the console highlights numbers and URLs, so with colour enabled the rendered output splits asserted substrings with escape codes and two tests fail - strip the codes before asserting so the result no longer depends on where the suite runs --- tests/test_ollama_base_url.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/test_ollama_base_url.py b/tests/test_ollama_base_url.py index 5dd0f85c8..c54162da6 100644 --- a/tests/test_ollama_base_url.py +++ b/tests/test_ollama_base_url.py @@ -3,9 +3,20 @@ from __future__ import annotations import importlib +import re import pytest +# Rich colorizes console output and highlights numbers and URLs, which splits +# asserted substrings with escape codes ("port \x1b[1;33m11434"). Whether it +# does so depends on the ambient terminal, so strip the codes to keep these +# assertions independent of where the suite runs. +_ANSI = re.compile(r"\x1b\[[0-9;]*m") + + +def _console_out(capsys) -> str: + return _ANSI.sub("", capsys.readouterr().out) + @pytest.fixture(scope="module", autouse=True) def _resync_reloaded_modules(): @@ -122,7 +133,7 @@ def test_confirm_endpoint_shows_default(monkeypatch, capsys): import cli.utils as cli_utils importlib.reload(cli_utils) cli_utils.confirm_ollama_endpoint("http://localhost:11434/v1") - out = capsys.readouterr().out + out = _console_out(capsys) assert "http://localhost:11434/v1" in out assert "OLLAMA_BASE_URL" not in out # not from env assert "Note" not in out # no warnings for the canonical default @@ -133,7 +144,7 @@ def test_confirm_endpoint_marks_env_origin(monkeypatch, capsys): import cli.utils as cli_utils importlib.reload(cli_utils) cli_utils.confirm_ollama_endpoint("http://remote-host:11434/v1") - out = capsys.readouterr().out + out = _console_out(capsys) assert "http://remote-host:11434/v1" in out assert "OLLAMA_BASE_URL" in out @@ -144,7 +155,7 @@ def test_confirm_endpoint_warns_on_missing_scheme(monkeypatch, capsys): import cli.utils as cli_utils importlib.reload(cli_utils) cli_utils.confirm_ollama_endpoint("0.0.0.128") - out = capsys.readouterr().out + out = _console_out(capsys) assert "missing a scheme" in out assert "http://:11434/v1" in out @@ -155,7 +166,7 @@ def test_confirm_endpoint_warns_on_non_default_port_remote(monkeypatch, capsys): import cli.utils as cli_utils importlib.reload(cli_utils) cli_utils.confirm_ollama_endpoint("http://remote-host/v1") - out = capsys.readouterr().out + out = _console_out(capsys) assert "port 11434" in out @@ -165,7 +176,7 @@ def test_confirm_endpoint_quiet_on_local_no_port(monkeypatch, capsys): import cli.utils as cli_utils importlib.reload(cli_utils) cli_utils.confirm_ollama_endpoint("http://localhost/v1") - out = capsys.readouterr().out + out = _console_out(capsys) assert "Note" not in out # localhost is fine without explicit port