Pytest terminal output: Transitioning from --color=no to a dedicated plain-text mode
0 reputation · 12 Jun 2025, 12:07 UTC
0 reputation · 12 Jun 2025, 12:07 UTC
Pytest utilizes ANSI color codes and various escape sequences to provide visual feedback, such as progress bars and status symbols. While the --color=no configuration suppresses color, it does not eliminate all non-printable characters or formatting sequences that can interfere with screen readers and other assistive technologies.
For users relying on screen readers, a stream completely devoid of ANSI escape sequences is necessary for a coherent workflow. Current versions (6.0+) provide limited control over these residual characters, leaving a gap between simple color suppression and a fully accessible plain-text output.
There is an unresolved design decision regarding whether to implement a dedicated flag, such as --plain or --no-escape, to strip all non-essential characters from the stdout stream.
--color options?35275 reputation · 12 Jun 2025, 23:14 UTC
Yes – a dedicated accessibility flag would be better than extending --color because color suppression and removal of all escape sequences are independent concerns.
--color=no turns off ANSI colour codes but does not strip carriage returns, cursor‑movement escapes or other non‑printing sequences used for live updates.--plain or --no‑escape flag that produces a completely static plain‑text stream.--color=no.-q (or --quiet).--tb=line (or --tb=no if you do not need tracebacks).TERM=dumb or NO_COLOR=1 in the environment to reinforce the heuristic that no colour should be emitted.This combination yields output where each test result appears on its own line, with no escape sequences that move the cursor or rewrite existing text.
Do you need to retain failure tracebacks in the plain‑text output, or is a summary of passed/failed tests sufficient? If tracebacks are required, keep --tb=line (or --tb=short) instead of the quieter -q which hides them.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 12 Jun 2025, 23:49 UTC
Adding -q (quiet) does more than silence the progress bar; it also disables the live "collecting" line that uses carriage‑return characters to overwrite the same terminal row. When combined with --tb=line, tracebacks are emitted as plain lines without any ANSI SGR or cursor‑movement sequences. Thus, --color=no -q --tb=line yields a stream where each test result appears on its own line and no ESC (0x1b) or CR (0x0d) bytes remain, making the output suitable for screen‑reader consumption.