GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add more docs · python/cpython@2201d8f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Doc/using
    • cmdline.rst
  • Lib/test
    • test_traceback.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Doc/using/cmdline.rst‎

Copy file name to clipboardExpand all lines: Doc/using/cmdline.rst
+20Lines changed: 20 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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
~~~~~~~~~~~~~~~~~~~~~~~~~
Collapse file

‎Lib/test/test_traceback.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_traceback.py
+18-17Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,24 +4314,25 @@ def foo():
43144314
self.assertEqual(actual, expected)
43154315

43164316
def test_colorized_detection_checks_for_environment_variables(self):
4317-
with unittest.mock.patch("os.isatty") as isatty_mock:
4318-
isatty_mock.return_value = True
4319-
with unittest.mock.patch("os.environ", {'TERM': 'dumb'}):
4317+
with unittest.mock.patch("nt._supports_virtual_terminal", return_value=True):
4318+
with unittest.mock.patch("os.isatty") as isatty_mock:
4319+
isatty_mock.return_value = True
4320+
with unittest.mock.patch("os.environ", {'TERM': 'dumb'}):
4321+
self.assertEqual(traceback._can_colorize(), False)
4322+
with unittest.mock.patch("os.environ", {'PY_COLORS': '1'}):
4323+
self.assertEqual(traceback._can_colorize(), True)
4324+
with unittest.mock.patch("os.environ", {'PY_COLORS': '0'}):
4325+
self.assertEqual(traceback._can_colorize(), False)
4326+
with unittest.mock.patch("os.environ", {'NO_COLOR': '1'}):
4327+
self.assertEqual(traceback._can_colorize(), False)
4328+
with unittest.mock.patch("os.environ", {'NO_COLOR': '1', "PY_COLORS": '1'}):
4329+
self.assertEqual(traceback._can_colorize(), False)
4330+
with unittest.mock.patch("os.environ", {'FORCE_COLOR': '1'}):
4331+
self.assertEqual(traceback._can_colorize(), True)
4332+
with unittest.mock.patch("os.environ", {'FORCE_COLOR': '1', 'NO_COLOR': '1'}):
4333+
self.assertEqual(traceback._can_colorize(), False)
4334+
isatty_mock.return_value = False
43204335
self.assertEqual(traceback._can_colorize(), False)
4321-
with unittest.mock.patch("os.environ", {'PY_COLORS': '1'}):
4322-
self.assertEqual(traceback._can_colorize(), True)
4323-
with unittest.mock.patch("os.environ", {'PY_COLORS': '0'}):
4324-
self.assertEqual(traceback._can_colorize(), False)
4325-
with unittest.mock.patch("os.environ", {'NO_COLOR': '1'}):
4326-
self.assertEqual(traceback._can_colorize(), False)
4327-
with unittest.mock.patch("os.environ", {'NO_COLOR': '1', "PY_COLORS": '1'}):
4328-
self.assertEqual(traceback._can_colorize(), False)
4329-
with unittest.mock.patch("os.environ", {'FORCE_COLOR': '1'}):
4330-
self.assertEqual(traceback._can_colorize(), True)
4331-
with unittest.mock.patch("os.environ", {'FORCE_COLOR': '1', 'NO_COLOR': '1'}):
4332-
self.assertEqual(traceback._can_colorize(), False)
4333-
isatty_mock.return_value = False
4334-
self.assertEqual(traceback._can_colorize(), False)
43354336

43364337
if __name__ == "__main__":
43374338
unittest.main()

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.