Skip to content

fix: disable Python 3.14 argparse colorization in tests - #17

Merged
mosquito merged 2 commits into
masterfrom
fix/py314-argparse-color-tests
Aug 20, 2026
Merged

fix: disable Python 3.14 argparse colorization in tests#17
mosquito merged 2 commits into
masterfrom
fix/py314-argparse-color-tests

Conversation

@mosquito

Copy link
Copy Markdown
Collaborator

Summary

  • The Test Python 3.14 on ubuntu-latest CI job was green only because that matrix leg is allow-failure: true — the actual pytest run was failing with 103 failed tests (exit code 1), silently masked by continue-on-error.
  • Root cause: Python 3.14's argparse colorizes --help/usage output by default (stdlib _colorize.can_colorize()), and this repo's CI workflow sets FORCE_COLOR: "1" globally for other tools. Two symptoms:
    • tests/test_doc_examples.py's flag_lexicon() regex can't match a flag immediately glued to a preceding ANSI escape code (e.g. \x1b[36m--file-excludes), so it silently drops flags from the parsed lexicon.
    • contree_cli.shell.repl.BUILTIN_HELP calls ArgumentParser.format_help() at module import time, baking the colorized (import-time) text into a module-level dict — a per-test fixture can't undo that afterward.
  • Fix: set PYTHON_COLORS=0 in tests/conftest.py before any contree_cli import (same pattern already used for CONTREE_HOME). PYTHON_COLORS takes precedence over FORCE_COLOR in the stdlib's own precedence order, so this is a clean override regardless of what CI sets.

Test plan

  • uv run --python 3.14 pytest -q under FORCE_COLOR=1: 1943 passed, 6 skipped (previously 103 failed)
  • uv run --python 3.10 pytest -q under FORCE_COLOR=1: unaffected, still passes (confirms no behavior change on versions without argparse colorization)
  • uv run ruff check / ruff format --check / mypy contree_cli: clean

Python 3.14's argparse colorizes --help/usage output by default,
honoring FORCE_COLOR (which CI sets globally for other tools). This
broke test_doc_examples.py's flag-extraction regex, which can't match
a flag glued to a preceding ANSI escape code, and baked colorized text
into contree_cli.shell.repl.BUILTIN_HELP at import time. Set
PYTHON_COLORS=0 in conftest.py before any contree_cli import, mirroring
the existing CONTREE_HOME pattern.
The allowance was masking 103 real test failures caused by argparse's
new colorized --help output; the prior commit fixes that at the root,
so 3.14 gates the build like every other matrix leg.
@mosquito
mosquito merged commit 7fc36fe into master Aug 20, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants