From 5ff8d872276bae9431e479e18e148e9802dbacfa Mon Sep 17 00:00:00 2001 From: Alpamys Date: Tue, 28 Apr 2026 13:25:54 +0500 Subject: [PATCH] fix(tests): strip ANSI in --log-level help-visible assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI's narrower terminal width forced Rich to split the flag literal across ANSI colour escapes (`\x1b[1;36m-\x1b[0m\x1b[1;36m-log\x1b[0m\x1b[1;36m-level\x1b[0m`), so the contiguous substring `--log-level` was not present in result.output even though the flag is registered correctly. Strip ANSI codes before the substring check — same pattern applied to similar Typer/Rich help-text tests in other Python projects. No code change. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/test_log_level.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_log_level.py b/tests/test_log_level.py index 5808284..1d338b3 100644 --- a/tests/test_log_level.py +++ b/tests/test_log_level.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging +import re import pytest from typer.testing import CliRunner @@ -16,6 +17,15 @@ from soup_cli.utils.log_level import ( setup_logging, ) +# Rich help renderer can split a flag like --log-level with ANSI colour +# escapes between `--`, `-log`, `-level` when the terminal is narrow (CI +# runners have a narrower default width than local shells). Strip ANSI so +# substring assertions are robust across all CI matrix jobs. +_ANSI_ESCAPE = re.compile(r"\x1b\[[0-9;]*[mK]") + + +def _strip_ansi(text: str) -> str: + return _ANSI_ESCAPE.sub("", text) class TestLogLevelEnum: def test_four_tiers_defined(self): @@ -86,7 +96,7 @@ class TestCliFlag: def test_log_level_help_visible(self): runner = CliRunner() result = runner.invoke(app, ["--help"]) - assert "--log-level" in result.output + assert "--log-level" in _strip_ansi(result.output), result.output def test_log_level_invalid_rejected(self): runner = CliRunner()