Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ae4c77

Browse files
committed
Add more docs
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parentff19eec commit9ae4c77

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

‎Doc/using/cmdline.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,26 @@ Miscellaneous options
612612
..versionadded::3.13
613613
The ``-X presite`` option.
614614

615+
Controlling Color
616+
~~~~~~~~~~~~~~~~~
617+
618+
The Python interpreter is configured by default to use colors to highlight
619+
output in certain situations such as when displaying tracebacks. This
620+
behavior can be controlled by setting different environment variables.
621+
622+
Setting the environment variable ``TERM`` to ``dumb`` will disable color.
623+
624+
If the environment variable ``FORCE_COLOR`` is set, then color will be
625+
enabled regardless of the value of TERM. This is useful on CI systems which
626+
aren’t terminals but can none-the-less display ANSI escape sequences.
627+
628+
If the environment variable ``NO_COLOR`` is set, Python will disable all color
629+
in the output. This takes precedence over ``FORCE_COLOR``.
630+
631+
All these environment variables are used also by other tools to control color
632+
output. To control the color output only in the Python interpreter, the
633+
:envvar:`PY_COLORS` environment variable can be used. This variable takes
634+
less precedence than ``NO_COLOR`` and ``FORCE_COLOR``.
615635

616636
Options you shouldn't use
617637
~~~~~~~~~~~~~~~~~~~~~~~~~

‎Lib/test/test_traceback.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
importjson
2626
importtextwrap
2727
importtraceback
28+
importcontextlib
2829
fromfunctoolsimportpartial
2930
frompathlibimportPath
3031

@@ -4314,24 +4315,29 @@ def foo():
43144315
self.assertEqual(actual,expected)
43154316

43164317
deftest_colorized_detection_checks_for_environment_variables(self):
4317-
withunittest.mock.patch("os.isatty")asisatty_mock:
4318-
isatty_mock.return_value=True
4319-
withunittest.mock.patch("os.environ", {'TERM':'dumb'}):
4320-
self.assertEqual(traceback._can_colorize(),False)
4321-
withunittest.mock.patch("os.environ", {'PY_COLORS':'1'}):
4322-
self.assertEqual(traceback._can_colorize(),True)
4323-
withunittest.mock.patch("os.environ", {'PY_COLORS':'0'}):
4324-
self.assertEqual(traceback._can_colorize(),False)
4325-
withunittest.mock.patch("os.environ", {'NO_COLOR':'1'}):
4326-
self.assertEqual(traceback._can_colorize(),False)
4327-
withunittest.mock.patch("os.environ", {'NO_COLOR':'1',"PY_COLORS":'1'}):
4328-
self.assertEqual(traceback._can_colorize(),False)
4329-
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1'}):
4330-
self.assertEqual(traceback._can_colorize(),True)
4331-
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1','NO_COLOR':'1'}):
4318+
ifsys.platform=="win32":
4319+
virtual_patching=unittest.mock.patch("nt._supports_virtual_terminal",return_value=True)
4320+
else:
4321+
virtual_patching=contextlib.nullcontext()
4322+
withvirtual_patching:
4323+
withunittest.mock.patch("os.isatty")asisatty_mock:
4324+
isatty_mock.return_value=True
4325+
withunittest.mock.patch("os.environ", {'TERM':'dumb'}):
4326+
self.assertEqual(traceback._can_colorize(),False)
4327+
withunittest.mock.patch("os.environ", {'PY_COLORS':'1'}):
4328+
self.assertEqual(traceback._can_colorize(),True)
4329+
withunittest.mock.patch("os.environ", {'PY_COLORS':'0'}):
4330+
self.assertEqual(traceback._can_colorize(),False)
4331+
withunittest.mock.patch("os.environ", {'NO_COLOR':'1'}):
4332+
self.assertEqual(traceback._can_colorize(),False)
4333+
withunittest.mock.patch("os.environ", {'NO_COLOR':'1',"PY_COLORS":'1'}):
4334+
self.assertEqual(traceback._can_colorize(),False)
4335+
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1'}):
4336+
self.assertEqual(traceback._can_colorize(),True)
4337+
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1','NO_COLOR':'1'}):
4338+
self.assertEqual(traceback._can_colorize(),False)
4339+
isatty_mock.return_value=False
43324340
self.assertEqual(traceback._can_colorize(),False)
4333-
isatty_mock.return_value=False
4334-
self.assertEqual(traceback._can_colorize(),False)
43354341

43364342
if__name__=="__main__":
43374343
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp