Skip to content

Commit a3fa85f

Browse files
tridgeclaude
andcommitted
scripts: keep PASSED/FAILED color when --timing pipes pytest output
--timing captures pytest's stdout through a Popen pipe so we can extract the durations section. pytest's --color=auto then sees a non-TTY on the other end of the pipe and turns ANSI color off, so green PASSED / red FAILED disappear in the user's terminal. Pass --color=yes when our own stdout is itself a TTY (so the user will see the codes rendered) but leave color off when the user is piping run_tests.py to a file or another process — same heuristic pytest's auto would have used if it could see past our capture. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0c303ec commit a3fa85f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

scripts/run_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,13 @@ def build_pytest_cmd(j, extra_args, target_args, timing=False):
130130
if n is not None:
131131
cmd += ['-n', str(n)]
132132
if timing:
133+
# We pipe pytest's output to capture it; pytest's --color=auto
134+
# then sees a non-TTY and turns colors off. Force them back on if
135+
# OUR own stdout is a TTY so the user still sees green PASSED /
136+
# red FAILED in interactive runs.
133137
cmd += ['--durations=0', '--durations-min=0']
138+
if sys.stdout.isatty():
139+
cmd += ['--color=yes']
134140
return cmd + extra_args + target_args
135141

136142

0 commit comments

Comments
 (0)