Skip to content

Setting color=True in runner.invoke on windows strips ansi codes #2705

@LilyFirefly

Description

@LilyFirefly

I am trying to test that a click command uses colors correctly. I've set the color=True argument to runner.invoke and this keeps the ansi escape codes as expected on Linux. However, on Windows these are completely stripped, as if color=False was set.

I did see #2606 and #2607, but testing the change there isn't enough to fix this for me. I think the problem is that color=True isn't set in the Context on Windows and therefore ctx.color is still None in resolve_color_default, despite color=True being passed to invoke.

Environment:

  • Python version: 3.8 - 3.12
  • Click version: 8.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions