Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No colors by default on GitHub Actions #7443

Closed
The-Compiler opened this issue Jul 3, 2020 · 10 comments
Closed

No colors by default on GitHub Actions #7443

The-Compiler opened this issue Jul 3, 2020 · 10 comments
Labels
type: enhancement new feature or API change, should be merged into features branch

Comments

@The-Compiler
Copy link
Member

The-Compiler commented Jul 3, 2020

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!)

@hugovk
Copy link
Member

hugovk commented Jul 8, 2020

Yep, this happens with pre-commit too, and many, many other tools. The problem is GitHub Actions does not provide a tty: actions/runner#241. This issue mentions pytest, and GitHub say it's low in their backlog and they have no plans to fix it (actions/runner#241 (comment)).

If you run pytest via tox, a similar workaround is to put it in config (eg. setup.cfg) so you don't need passenv:

@hugovk
Copy link
Member

hugovk commented Jul 8, 2020

Please see PR #7462.

@eine
Copy link

eine commented Jul 8, 2020

IMHO, envvars to force colouring are VERY inconsistent. This is true even in the Python ecosystem. For example, see this issue, tartley/colorama#230 (/cc @jhol @tartley @wiggin15 @eric-wieser), tox-dev/tox#1468 (/cc @gaborbernat)... I believe it would be desirable if the community could talk and agree on a couple of envvars.

I like @jhol's FORCE_COLOR and NO_COLOR.

@The-Compiler
Copy link
Member Author

@eine True, but this seems unrelated to this issue?

@Zac-HD Zac-HD added the type: enhancement new feature or API change, should be merged into features branch label Jul 8, 2020
@eine
Copy link

eine commented Jul 8, 2020

@The-Compiler, I believe it is! Should pytest work with FORCE_COLOR (and tox and colorama too), PYTEST_ADDOPTS or --color=yes would not be required. At the same time, if checking TERM or asking GitHub to define FORCE_COLOR is the way to go, all projects (including pytest) could benefit from it. #7462 is a legit workaround, but an ad-hoc fix after all.

EDIT

FTR:

@jhol
Copy link

jhol commented 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.

@nicoddemus
Copy link
Member

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

@nicoddemus
Copy link
Member

I think based on the discussions on #7462, we can close this as "wontfix" because pytest can't reliably detect this in GitHub actions. What do you think @The-Compiler ?

@eine
Copy link

eine commented Jul 10, 2020

Agree. As @The-Compiler commented in #7462 (comment), I think that the following is the way to go:

env:
  PY_COLORS: "1"

For example: https://github.com/VUnit/vunit/blob/master/.github/workflows/push.yml#L12

When/if tox supports it:

env:
  FORCE_COLOR: "1"

@The-Compiler
Copy link
Member Author

Sounds reasonable!

The-Compiler added a commit to The-Compiler/pytest that referenced this issue May 4, 2021
The-Compiler added a commit to The-Compiler/pytest that referenced this issue May 4, 2021
The-Compiler added a commit to The-Compiler/pytest that referenced this issue May 4, 2021
bwoodsend pushed a commit to pyinstaller/pyinstaller that referenced this issue Jun 16, 2022
weiji14 added a commit to GenericMappingTools/pygmt that referenced this issue Jul 16, 2024
GitHub Actions does not show colour outputs for pytest by default (pytest-dev/pytest#7443), but it can be enabled using `--color=yes` flag.
weiji14 added a commit to GenericMappingTools/pygmt that referenced this issue Jul 16, 2024
…lor (#3330)

GitHub Actions does not show colour outputs for pytest by default
(pytest-dev/pytest#7443), but it can be
enabled using `--color=yes` flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants