test(propose-segments): the arm-attribution test reads --help without colour

Python 3.14's argparse colours `--help` when FORCE_COLOR is set, and a
background session inherits FORCE_COLOR=3. An escape code then stands
before ` --outline-run`, no option chunk starts with the flag, and
test_each_arm_flag_carries_its_attribution_inside_its_own_option_chunk
fails -- also on v1.1.0. The test now sets PYTHON_COLORS=0, the variable
_colorize.can_colorize reads first, so it outranks FORCE_COLOR and
NO_COLOR alike; what --help says is unchanged and src/ is untouched.

Chosen over stripping ANSI codes before comparing, because that would
restate Python's escape grammar in the test.

Measured, full suite: before the fix FORCE_COLOR=3 gives 1 failed / 2449
passed / 1 skipped, and this is the only colour-dependent test. After
git add: 2450 passed / 1 skipped both with FORCE_COLOR=3 and without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-09-23 08:36:59 +02:00
commit ef76a24d72
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q

View file

@ -1071,6 +1071,7 @@ ARM_ATTRIBUTION = {
def test_each_arm_flag_carries_its_attribution_inside_its_own_option_chunk(
capsys: pytest.CaptureFixture[str],
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Each attribution must sit in its own option's help, not merely in the file.
@ -1084,7 +1085,15 @@ def test_each_arm_flag_carries_its_attribution_inside_its_own_option_chunk(
written down. A hard-coded `== 1` is correct only until a second arm is
attributed the same way, and it then goes red on an axis that has nothing
to do with whether the new arm is right.
Colour is switched off for the call. Python 3.14's argparse colours
`--help` when `FORCE_COLOR` is set -- a background session inherits
`FORCE_COLOR=3` -- and an escape code before ` --outline-run` leaves no
chunk starting with the flag. `PYTHON_COLORS=0` is the variable
`_colorize.can_colorize` reads FIRST, so it outranks `FORCE_COLOR` and
`NO_COLOR` alike; the help's words are the same either way.
"""
monkeypatch.setenv("PYTHON_COLORS", "0")
with pytest.raises(SystemExit) as exit_info:
okf_propose_segments.main(["--help"])
assert exit_info.value.code == 0