Skip to content

Commit 15c840a

Browse files
committed
Deactivate on -E
1 parent ee4966a commit 15c840a

13 files changed

+11
-49
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from test.support import import_helper
2626
from test.support import threading_helper
2727
from test.support import warnings_helper
28-
from test.support import force_not_colorized
2928
from test.support import requires_limited_api
3029
from test.support.script_helper import assert_python_failure, assert_python_ok, run_python_until_end
3130
try:
@@ -206,7 +205,6 @@ def test_c_type_with_ipow(self):
206205
self.assertEqual(o.__ipow__(1), (1, None))
207206
self.assertEqual(o.__ipow__(2, 2), (2, 2))
208207

209-
@force_not_colorized
210208
def test_return_null_without_error(self):
211209
# Issue #23571: A function must not return NULL without setting an
212210
# error
@@ -236,7 +234,6 @@ def test_return_null_without_error(self):
236234
'return_null_without_error.* '
237235
'returned NULL without setting an exception')
238236

239-
@force_not_colorized
240237
def test_return_result_with_error(self):
241238
# Issue #23571: A function must not return a result with an error set
242239
if support.Py_DEBUG:
@@ -271,7 +268,6 @@ def test_return_result_with_error(self):
271268
'return_result_with_error.* '
272269
'returned a result with an exception set')
273270

274-
@force_not_colorized
275271
def test_getitem_with_error(self):
276272
# Test _Py_CheckSlotResult(). Raise an exception and then calls
277273
# PyObject_GetItem(): check that the assertion catches the bug.

Lib/test/test_cmd_line_script.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import textwrap
1616
from test import support
17-
from test.support import import_helper, is_apple, os_helper, force_not_colorized
17+
from test.support import import_helper, is_apple, os_helper
1818
from test.support.script_helper import (
1919
make_pkg, make_script, make_zip_pkg, make_zip_script,
2020
assert_python_ok, assert_python_failure, spawn_python, kill_python)
@@ -195,7 +195,6 @@ def check_repl_stdout_flush(self, separate_stderr=False):
195195
p.stdin.flush()
196196
self.assertEqual(b'foo', p.stdout.readline().strip())
197197

198-
@force_not_colorized
199198
def check_repl_stderr_flush(self, separate_stderr=False):
200199
with self.interactive_python(separate_stderr) as p:
201200
p.stdin.write(b"1/0\n")
@@ -538,7 +537,6 @@ def test_dash_m_main_traceback(self):
538537
self.assertIn(b'Exception in __main__ module', err)
539538
self.assertIn(b'Traceback', err)
540539

541-
@force_not_colorized
542540
def test_pep_409_verbiage(self):
543541
# Make sure PEP 409 syntax properly suppresses
544542
# the context of an exception
@@ -604,7 +602,6 @@ def test_issue20500_exit_with_exception_value(self):
604602
text = stderr.decode('ascii')
605603
self.assertEqual(text.rstrip(), "some text")
606604

607-
@force_not_colorized
608605
def test_syntaxerror_unindented_caret_position(self):
609606
script = "1 + 1 = 2\n"
610607
with os_helper.temp_dir() as script_dir:
@@ -614,7 +611,6 @@ def test_syntaxerror_unindented_caret_position(self):
614611
# Confirm that the caret is located under the '=' sign
615612
self.assertIn("\n ^^^^^\n", text)
616613

617-
@force_not_colorized
618614
def test_syntaxerror_indented_caret_position(self):
619615
script = textwrap.dedent("""\
620616
if True:
@@ -638,7 +634,6 @@ def test_syntaxerror_indented_caret_position(self):
638634
self.assertNotIn("\f", text)
639635
self.assertIn("\n 1 + 1 = 2\n ^^^^^\n", text)
640636

641-
@force_not_colorized
642637
def test_syntaxerror_multi_line_fstring(self):
643638
script = 'foo = f"""{}\nfoo"""\n'
644639
with os_helper.temp_dir() as script_dir:
@@ -653,7 +648,6 @@ def test_syntaxerror_multi_line_fstring(self):
653648
],
654649
)
655650

656-
@force_not_colorized
657651
def test_syntaxerror_invalid_escape_sequence_multi_line(self):
658652
script = 'foo = """\\q"""\n'
659653
with os_helper.temp_dir() as script_dir:
@@ -669,7 +663,6 @@ def test_syntaxerror_invalid_escape_sequence_multi_line(self):
669663
],
670664
)
671665

672-
@force_not_colorized
673666
def test_syntaxerror_null_bytes(self):
674667
script = "x = '\0' nothing to see here\n';import os;os.system('echo pwnd')\n"
675668
with os_helper.temp_dir() as script_dir:
@@ -682,7 +675,6 @@ def test_syntaxerror_null_bytes(self):
682675
],
683676
)
684677

685-
@force_not_colorized
686678
def test_syntaxerror_null_bytes_in_multiline_string(self):
687679
scripts = ["\n'''\nmultilinestring\0\n'''", "\nf'''\nmultilinestring\0\n'''"] # Both normal and f-strings
688680
with os_helper.temp_dir() as script_dir:
@@ -696,7 +688,6 @@ def test_syntaxerror_null_bytes_in_multiline_string(self):
696688
]
697689
)
698690

699-
@force_not_colorized
700691
def test_source_lines_are_shown_when_running_source(self):
701692
_, _, stderr = assert_python_failure("-c", "1/0")
702693
expected_lines = [
@@ -707,7 +698,6 @@ def test_source_lines_are_shown_when_running_source(self):
707698
b'ZeroDivisionError: division by zero']
708699
self.assertEqual(stderr.splitlines(), expected_lines)
709700

710-
@force_not_colorized
711701
def test_syntaxerror_does_not_crash(self):
712702
script = "nonlocal x\n"
713703
with os_helper.temp_dir() as script_dir:

Lib/test/test_compileall.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from test import support
3030
from test.support import os_helper
3131
from test.support import script_helper
32-
from test.support import force_not_colorized
3332
from test.test_py_compile import without_source_date_epoch
3433
from test.test_py_compile import SourceDateEpochTestMeta
3534

@@ -761,7 +760,6 @@ def test_d_compile_error(self):
761760
rc, out, err = self.assertRunNotOK('-q', '-d', 'dinsdale', self.pkgdir)
762761
self.assertRegex(out, b'File "dinsdale')
763762

764-
@force_not_colorized
765763
def test_d_runtime_error(self):
766764
bazfn = script_helper.make_script(self.pkgdir, 'baz', 'raise Exception')
767765
self.assertRunOK('-q', '-d', 'dinsdale', self.pkgdir)

Lib/test/test_eof.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from test.support import os_helper
66
from test.support import script_helper
77
from test.support import warnings_helper
8-
from test.support import force_not_colorized
98
import unittest
109

1110
class EOFTestCase(unittest.TestCase):
@@ -59,7 +58,6 @@ def test_line_continuation_EOF(self):
5958
self.assertEqual(str(excinfo.exception), expect)
6059

6160
@unittest.skipIf(not sys.executable, "sys.executable required")
62-
@force_not_colorized
6361
def test_line_continuation_EOF_from_file_bpo2180(self):
6462
"""Ensure tok_nextc() does not add too many ending newlines."""
6563
with os_helper.temp_dir() as temp_dir:

Lib/test/test_exceptions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,6 @@ def gen():
14401440

14411441
@cpython_only
14421442
@unittest.skipIf(_testcapi is None, "requires _testcapi")
1443-
@force_not_colorized
14441443
def test_recursion_normalizing_infinite_exception(self):
14451444
# Issue #30697. Test that a RecursionError is raised when
14461445
# maximum recursion depth has been exceeded when creating
@@ -2197,7 +2196,6 @@ def test_range_of_offsets(self):
21972196
self.assertIn(expected, err.getvalue())
21982197
the_exception = exc
21992198

2200-
@force_not_colorized
22012199
def test_encodings(self):
22022200
source = (
22032201
'# -*- coding: cp437 -*-\n'
@@ -2227,7 +2225,6 @@ def test_encodings(self):
22272225
finally:
22282226
unlink(TESTFN)
22292227

2230-
@force_not_colorized
22312228
def test_non_utf8(self):
22322229
# Check non utf-8 characters
22332230
try:

Lib/test/test_inspect/test_inspect.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from test.support.os_helper import TESTFN, temp_cwd
3939
from test.support.script_helper import assert_python_ok, assert_python_failure, kill_python
4040
from test.support import has_subprocess_support, SuppressCrashReport
41-
from test.support import force_not_colorized
4241
from test import support
4342

4443
from test.test_inspect import inspect_fodder as mod
@@ -817,7 +816,6 @@ def test_getsource_on_code_object(self):
817816
self.assertSourceEqual(mod.eggs.__code__, 12, 18)
818817

819818
class TestGetsourceInteractive(unittest.TestCase):
820-
@force_not_colorized
821819
def test_getclasses_interactive(self):
822820
# bpo-44648: simulate a REPL session;
823821
# there is no `__file__` in the __main__ module

Lib/test/test_regrtest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import unittest
2424
from test import support
2525
from test.support import os_helper, without_optimizer
26-
from test.support import force_not_colorized
2726
from test.libregrtest import cmdline
2827
from test.libregrtest import main
2928
from test.libregrtest import setup
@@ -1836,7 +1835,6 @@ def test_unraisable_exc(self):
18361835
self.assertIn("Warning -- Unraisable exception", output)
18371836
self.assertIn("Exception: weakref callback bug", output)
18381837

1839-
@force_not_colorized
18401838
def test_threading_excepthook(self):
18411839
# --fail-env-changed must catch uncaught thread exception.
18421840
# The exception must be displayed even if sys.stderr is redirected.

Lib/test/test_repl.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from textwrap import dedent
88
from test import support
99
from test.support import cpython_only, has_subprocess_support, SuppressCrashReport
10-
from test.support import force_not_colorized
1110
from test.support.script_helper import kill_python
1211
from test.support.import_helper import import_module
1312

@@ -16,7 +15,6 @@
1615
raise unittest.SkipTest("test module requires subprocess")
1716

1817

19-
@force_not_colorized
2018
def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
2119
"""Run the Python REPL with the given arguments.
2220
@@ -45,7 +43,6 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
4543
stdout=stdout, stderr=stderr,
4644
**kw)
4745

48-
@force_not_colorized
4946
def run_on_interactive_mode(source):
5047
"""Spawn a new Python interpreter, pass the given
5148
input source code from the stdin and return the

Lib/test/test_runpy.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
import unittest
1414
import warnings
1515
from test.support import (infinite_recursion, no_tracing, verbose,
16-
requires_subprocess, requires_resource,
17-
force_not_colorized)
16+
requires_subprocess, requires_resource)
1817
from test.support.import_helper import forget, make_legacy_pyc, unload
1918
from test.support.os_helper import create_empty_file, temp_dir
2019
from test.support.script_helper import make_script, make_zip_script
@@ -787,7 +786,6 @@ def run(self, *args, **kwargs):
787786
super().run(*args, **kwargs)
788787

789788
@requires_subprocess()
790-
@force_not_colorized
791789
def assertSigInt(self, cmd, *args, **kwargs):
792790
# Use -E to ignore PYTHONSAFEPATH
793791
cmd = [sys.executable, '-E', *cmd]
@@ -798,7 +796,6 @@ def assertSigInt(self, cmd, *args, **kwargs):
798796
def test_pymain_run_file(self):
799797
self.assertSigInt([self.ham])
800798

801-
@force_not_colorized
802799
def test_pymain_run_file_runpy_run_module(self):
803800
tmp = self.ham.parent
804801
run_module = tmp / "run_module.py"
@@ -812,7 +809,6 @@ def test_pymain_run_file_runpy_run_module(self):
812809
)
813810
self.assertSigInt([run_module], cwd=tmp)
814811

815-
@force_not_colorized
816812
def test_pymain_run_file_runpy_run_module_as_main(self):
817813
tmp = self.ham.parent
818814
run_module_as_main = tmp / "run_module_as_main.py"
@@ -826,22 +822,18 @@ def test_pymain_run_file_runpy_run_module_as_main(self):
826822
)
827823
self.assertSigInt([run_module_as_main], cwd=tmp)
828824

829-
@force_not_colorized
830825
def test_pymain_run_command_run_module(self):
831826
self.assertSigInt(
832827
["-c", "import runpy; runpy.run_module('ham')"],
833828
cwd=self.ham.parent,
834829
)
835830

836-
@force_not_colorized
837831
def test_pymain_run_command(self):
838832
self.assertSigInt(["-c", "import ham"], cwd=self.ham.parent)
839833

840-
@force_not_colorized
841834
def test_pymain_run_stdin(self):
842835
self.assertSigInt([], input="import ham", cwd=self.ham.parent)
843836

844-
@force_not_colorized
845837
def test_pymain_run_module(self):
846838
ham = self.ham
847839
self.assertSigInt(["-m", ham.stem], cwd=ham.parent)

Lib/test/test_traceback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def test_encoded_file(self):
396396
process = subprocess.Popen([sys.executable, "-c",
397397
"import sys; print(sys.stdout.encoding)"],
398398
stdout=subprocess.PIPE,
399-
stderr=subprocess.STDOUT, env={})
399+
stderr=subprocess.STDOUT)
400400
stdout, stderr = process.communicate()
401401
output_encoding = str(stdout, 'ascii').splitlines()[0]
402402

Lib/test/test_tracemalloc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
interpreter_requires_environment)
99
from test import support
1010
from test.support import os_helper
11-
from test.support import force_not_colorized
1211

1312
try:
1413
import _testcapi
@@ -980,7 +979,6 @@ def check_sys_xoptions_invalid(self, nframe):
980979
return
981980
self.fail(f"unexpected output: {stderr!a}")
982981

983-
@force_not_colorized
984982
def test_sys_xoptions_invalid(self):
985983
for nframe in INVALID_NFRAME:
986984
with self.subTest(nframe=nframe):

Lib/test/test_unicodedata.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import unicodedata
1313
import unittest
1414
from test.support import (open_urlresource, requires_resource, script_helper,
15-
cpython_only, check_disallow_instantiation, force_not_colorized)
15+
cpython_only, check_disallow_instantiation)
1616

1717

1818
class UnicodeMethodsTest(unittest.TestCase):
@@ -277,7 +277,6 @@ def test_disallow_instantiation(self):
277277
# Ensure that the type disallows instantiation (bpo-43916)
278278
check_disallow_instantiation(self, unicodedata.UCD)
279279

280-
@force_not_colorized
281280
def test_failed_import_during_compiling(self):
282281
# Issue 4367
283282
# Decoding \N escapes requires the unicodedata module. If it can't be

Lib/traceback.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ def _can_colorize():
146146
return False
147147
if os.environ.get("PYTHON_COLORS") == "1":
148148
return True
149-
if "NO_COLOR" in os.environ:
150-
return False
149+
if "NO_COLOR" in os.environ:
150+
return False
151151
if not _COLORIZE:
152152
return False
153-
if "FORCE_COLOR" in os.environ:
154-
return True
155-
if os.environ.get("TERM") == "dumb":
156-
return False
153+
if not sys.flags.ignore_environment:
154+
if "FORCE_COLOR" in os.environ:
155+
return True
156+
if os.environ.get("TERM") == "dumb":
157+
return False
157158
try:
158159
return os.isatty(sys.stderr.fileno())
159160
except io.UnsupportedOperation:

0 commit comments

Comments
 (0)