No colors by default on GitHub Actions
See original GitHub issueWhen running pytest on GitHub Actions (like we do ourselves, random example), the output is not colored.
pytest does color output on Travis CI by default, so it could be argued that this is somehow GitHub Action’s fault. However, other tools (e.g. eslint
, and I think mypy
) seem to colorize their output on GitHub actions just fine, without needing to force them! From what I’ve seen, those tools seem to be influenced by the TERM
environment variable, while pytest’s (or pylib’s?) autodetection seems to work differently?
As a workaround, this helps (as part of the step definition):
- name: "Run pytest"
env:
PYTEST_ADDOPTS: "--color=yes"
run: pytest
(If you run pytest via tox, make sure to add PYTEST_ADDOPTS
to passenv
!)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Set the environment variable to enable colorful output by default
Setting below environment variables will enable colorful output when running on GitHub Actions (not on Windows though):.
Read more >Add optional support for colourised output (where available...)
This is interesting, and I'll need to take a look at how the logging works with GitHub Actions. I haven't seen any way...
Read more >Workflow syntax for GitHub Actions
When a pattern matches the branches-ignore pattern, the workflow will not run. The patterns defined in branches are evaluated against the Git ref's...
Read more >Enable console color output by default · actions/setup-dotnet ...
Set up your GitHub Actions workflow with a specific version of the .NET core sdk - Enable console color output by default ·...
Read more >ANSI color output in webview?!? · Discussion #26944 - GitHub
So somehow with the default environment of GitHub Actions mocha could not identify itself that it is running within a TTY enabled device...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @jhol and @eine for bringing this up. I’ve created #7464 to track adding this support to pytest. 👍
NO_COLOR
is a community standard environement variable.The general behavior is:
NO_COLOR
stops the application from emitting colour even when attached to a TTYFORCE_COLOR
which forces the application to emit colour escape sequences even when not outputting to a TTY e.g. if we want to pipe into a log file with colour.