question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No colors by default on GitHub Actions

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
nicoddemuscommented, Jul 8, 2020

Thanks @jhol and @eine for bringing this up. I’ve created #7464 to track adding this support to pytest. 👍

2reactions
jholcommented, Jul 8, 2020

NO_COLOR is a community standard environement variable.

The general behavior is:

  • A command line application emits colour when attached to a TTY, but no colour otherwise e.g. when attached to a pipe.
  • NO_COLOR stops the application from emitting colour even when attached to a TTY
  • My extension to the standard is to add FORCE_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.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found