Skip to content

Fix test_help_in_readme failing due to ANSI color codes in Python 3.13 argparse output#164

Merged
jaraco merged 2 commits intomainfrom
copilot/fix-readme-help-test-failure
Mar 7, 2026
Merged

Fix test_help_in_readme failing due to ANSI color codes in Python 3.13 argparse output#164
jaraco merged 2 commits intomainfrom
copilot/fix-readme-help-test-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 7, 2026

Python 3.13's argparse emits ANSI color escape codes in help output when running in a color-capable environment. test_help_in_readme compares csv2ofx --help output directly against the plain-text README, causing it to fail in CI where color is enabled.

Changes

  • tests/test_cli.py: Set NO_COLOR=1 in the subprocess environment when capturing --help output in test_help_in_readme, stripping ANSI codes so the output matches the README's plain text.
def test_help_in_readme():
    env = {**os.environ, "NO_COLOR": "1"}
    out = subprocess.check_output(['csv2ofx', '--help'], text=True, env=env)
    readme = pathlib.Path('README.md').read_text()
    assert out in readme, "README help is stale, please update."
Original prompt

This section details on the original issue you should resolve

<issue_title>Failure in tests checking README usage is not stale</issue_title>
<issue_description>The test_help_in_readme has started failing with:

FAILED tests/test_cli.py::test_help_in_readme - AssertionError: README help is stale, please update.

It passes for me locally, but not in CI. The tests are explicitly disabled on Python 3.13 and earlier (due to a change in how argparser renders things). But now it appears to be failing in CI due to the presence of ANSI color control characters:

_____________________________ test_help_in_readme ______________________________

    @pytest.mark.xfail("sys.version_info < (3, 13)")
    def test_help_in_readme():
        out = subprocess.check_output(['csv2ofx', '--help'], text=True)
        readme = pathlib.Path('README.md').read_text()
>       assert out in readme, "README help is stale, please update."
E       AssertionError: README help is stale, please update.
E       assert '\x1b[1;34musage: \x1b[0m\x1b[35m\x1b[1;35mcsv2ofx\x1b[0m\x1b[35m [options] <source> <dest>\x1b[0m\n\ndescription: csv...options and arguments passed to the parser\n  \x1b[1;32m-v\x1b[0m, \x1b[1;36m--verbose\x1b[0m         verbose output\n' in '# csv2ofx\n\n[![GHA](https://github.com/reubano/csv2ofx/actions/workflows/main.yml/badge.svg)](https://github.com/reu...ed under the [MIT License](http://opensource.org/licenses/MIT), the same as [meza](https://github.com/reubano/meza).\n'

tests/test_cli.py:163: AssertionError

Probably the test should be updated to disable color output when rendering the help text.</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: jaraco <308610+jaraco@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failure in tests checking README usage is not stale Fix test_help_in_readme failing due to ANSI color codes in Python 3.13 argparse output Mar 7, 2026
@jaraco jaraco marked this pull request as ready for review March 7, 2026 22:28
@jaraco jaraco merged commit 5cbccc2 into main Mar 7, 2026
27 checks passed
@jaraco jaraco deleted the copilot/fix-readme-help-test-failure branch March 7, 2026 22:29
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.

Failure in tests checking README usage is not stale

2 participants