Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions Lib/test/libregrtest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import unittest
from test import support
from test.support.os_helper import TESTFN_UNDECODABLE, FS_NONASCII
from _colorize import can_colorize # type: ignore[import-not-found]

from .filter import set_match_tests
from .runtests import RunTests
Expand Down Expand Up @@ -139,3 +140,6 @@ def setup_tests(runtests: RunTests) -> None:
gc.set_threshold(runtests.gc_threshold)

random.seed(runtests.random_seed)

if can_colorize(file=sys.stdout):
os.environ['FORCE_COLOR'] = "1"
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Update ``python -m test`` to set ``FORCE_COLOR=1`` when being run with color
enabled so that :mod:`unittest` which is run by it with redirected output will
output in color.
Loading