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.

cannot see ansi colors in the stdout capture call

See original GitHub issue

i had run pytest with --color=yes in terminal and some of my tests where printing something on stdout, pytest captured the output, but ansi colors where not present.

here was the full command: pytest -vv -x -rP --color=yes --durations=0

does pytest have ansi color output support from stdout call capture ?

here im testing a function that prints colored output in my terminal image

but not in pytest captured stdout call image

or maybe im using the wrong flag …

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Jan 7, 2022

even if this were possible to change within pytest it would be a big breaking change to consumers of pytest if the default isatty were to change (for which the current assumption is isatty=False)

usually it’s best to individually test the coloring via mocking isatty or whatever trigger your coloring code uses – for example from all-repos or from pre-commit

0reactions
asottilecommented, Jan 7, 2022

it wouldn’t work for all methods of color detection – only for those which use isatty (for instance some do color detection via curses or via tput)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python module to enable ANSI colors for stdout on Windows?
Your best bet is probably to use the colorama module. In fact, I believe that the Windows console does not support ANSI colors...
Read more >
when output filename is set, ANSI color codes are printed to ...
Describe the bug When Catch output is redirected to a file via the --out option and color output is forced via --use-colour=yes, the...
Read more >
Can less retain colored output? - Unix & Linux Stack Exchange
Use: git diff --color=always | less -r. --color=always is there to tell git to output color codes even if the output is a...
Read more >
Windows console with ANSI colors handling - Super User
For Windows version below 10, the Windows command console doesn't support output coloring by default. You could install either Cmder, ConEmu, ANSICON or...
Read more >
Is there a way to preserve text color codes on piped stdout ...
If a process can auto-detect if it is in a interactive terminal or not and adjust color output it will most likely have...
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