File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ def use_color(setting):
4848 if setting not in COLOR_CHOICES :
4949 raise InvalidColorSetting (setting )
5050
51+ if os .environ .get ('NO_COLOR' ):
52+ return False
53+
5154 return (
5255 setting == 'always' or
5356 (setting == 'auto' and sys .stdout .isatty () and terminal_supports_color )
Original file line number Diff line number Diff line change 11from __future__ import unicode_literals
22
3+ import os
34import sys
45
56import mock
@@ -50,3 +51,18 @@ def test_use_color_tty_without_color_support():
5051def test_use_color_raises_if_given_shenanigans ():
5152 with pytest .raises (InvalidColorSetting ):
5253 use_color ('herpaderp' )
54+
55+
56+ def test_no_color_env_unset ():
57+ with mock .patch .dict (os .environ , clear = True ):
58+ assert use_color ('always' ) is True
59+
60+
61+ def test_no_color_env_empty ():
62+ with mock .patch .dict (os .environ , NO_COLOR = '' ):
63+ assert use_color ('always' ) is True
64+
65+
66+ def test_no_color_env_non_empty ():
67+ with mock .patch .dict (os .environ , NO_COLOR = ' ' ):
68+ assert use_color ('always' ) is False
You can’t perform that action at this time.
0 commit comments