@@ -57,6 +57,7 @@ def verify_valid_flag(self, cmd_line):
5757 return out
5858
5959 @support .cpython_only
60+ @support .force_not_colorized
6061 def test_help (self ):
6162 self .verify_valid_flag ('-h' )
6263 self .verify_valid_flag ('-?' )
@@ -68,6 +69,7 @@ def test_help(self):
6869 self .assertLess (len (lines ), 50 )
6970
7071 @support .cpython_only
72+ @support .force_not_colorized
7173 def test_help_env (self ):
7274 out = self .verify_valid_flag ('--help-env' )
7375 self .assertIn (b'PYTHONHOME' , out )
@@ -81,6 +83,7 @@ def test_help_env(self):
8183 "env vars should be sorted alphabetically" )
8284
8385 @support .cpython_only
86+ @support .force_not_colorized
8487 def test_help_xoptions (self ):
8588 out = self .verify_valid_flag ('--help-xoptions' )
8689 self .assertIn (b'-X dev' , out )
@@ -89,6 +92,7 @@ def test_help_xoptions(self):
8992 "options should be sorted alphabetically" )
9093
9194 @support .cpython_only
95+ @support .force_not_colorized
9296 def test_help_all (self ):
9397 out = self .verify_valid_flag ('--help-all' )
9498 lines = out .splitlines ()
@@ -100,6 +104,25 @@ def test_help_all(self):
100104 # but the rest should be ASCII-only
101105 b'' .join (lines [1 :]).decode ('ascii' )
102106
107+ @support .cpython_only
108+ @support .force_colorized
109+ def test_help_colorized (self ):
110+ rc , out , err = assert_python_ok ("--help" , FORCE_COLOR = "1" )
111+ # Check ANSI color codes are present
112+ self .assertIn (b"\x1b [" , out )
113+ # Check that key text elements are still present
114+ self .assertIn (b"usage:" , out )
115+ self .assertIn (b"-h" , out )
116+ self .assertIn (b"--help-all" , out )
117+ self .assertIn (b"cmd" , out )
118+ self .assertIn (b"Arguments:" , out )
119+
120+ @support .cpython_only
121+ @support .force_not_colorized
122+ def test_help_not_colorized (self ):
123+ rc , out , err = assert_python_ok ("--help" )
124+ self .assertNotIn (b"\x1b [" , out )
125+
103126 def test_optimize (self ):
104127 self .verify_valid_flag ('-O' )
105128 self .verify_valid_flag ('-OO' )
@@ -1063,6 +1086,7 @@ def test_argv0_normalization(self):
10631086 self .assertEqual (proc .stdout .strip (), b'0' )
10641087
10651088 @support .cpython_only
1089+ @support .force_not_colorized
10661090 def test_parsing_error (self ):
10671091 args = [sys .executable , '-I' , '--unknown-option' ]
10681092 proc = subprocess .run (args ,
0 commit comments