Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Lib/test/libregrtest/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import gc
import importlib
import io
import os
import sys
import time
import traceback
import unittest

from _colorize import get_colors # type: ignore[import-not-found]
from _colorize import can_colorize, get_colors # type: ignore[import-not-found]
from test import support
from test.support import threading_helper

Expand Down Expand Up @@ -274,6 +275,9 @@ def _runtest(result: TestResult, runtests: RunTests) -> None:
output_on_failure = runtests.output_on_failure
timeout = runtests.timeout

if can_colorize(file=sys.stdout):
os.environ['FORCE_COLOR'] = "1"

if timeout is not None and threading_helper.can_start_thread:
use_timeout = True
faulthandler.dump_traceback_later(timeout, exit=True)
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/libregrtest/worker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys
import os
from _colorize import can_colorize # type: ignore[import-not-found]
from typing import Any, NoReturn

from test.support import os_helper, Py_DEBUG
Expand Down Expand Up @@ -32,6 +33,12 @@ def create_worker_process(runtests: WorkerRunTests, output_fd: int,
env['TEMP'] = tmp_dir
env['TMP'] = tmp_dir

# The subcommand is run with a temporary output which means it is not a tty
# and won't auto-color. The test results are printed to stdout so if we can
# color that have the subprocess use color.
if can_colorize(file=sys.stdout):
env['FORCE_COLOR'] = '1'

# Running the child from the same working directory as regrtest's original
# invocation ensures that TEMPDIR for the child is the same when
# sysconfig.is_python_build() is true. See issue 15300.
Expand Down
Loading