Skip to content

Commit 71d1e92

Browse files
pmppkjacobtylerwalls
authored andcommitted
Refs #36936 - Adjusted tests to set PYTHON_COLORS environment variable.
When "FORCE_COLOR" was set in the environment (such as in django-docker-box) several test cases that rely on string comparisons against exception messages or command line results would fail due to ANSI escape sequences being present in the output. This change resolved the issue by setting the "PYTHON_COLORS" environment variable to "0" for those specific tests, which takes precendence over the presence of "FORCE_COLOR".
1 parent e6108b7 commit 71d1e92

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

tests/admin_scripts/tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def run_test(self, args, settings_file=None, apps=None, umask=-1):
134134
python_path.extend(ext_backend_base_dirs)
135135
test_environ["PYTHONPATH"] = os.pathsep.join(python_path)
136136
test_environ["PYTHONWARNINGS"] = ""
137+
test_environ["PYTHON_COLORS"] = "0"
137138

138139
p = subprocess.run(
139140
[sys.executable, *args],
@@ -2551,6 +2552,7 @@ def _test(self, args, option_b="'2'"):
25512552
)
25522553

25532554

2555+
@mock.patch.dict(os.environ, {"PYTHON_COLORS": "0"})
25542556
class ExecuteFromCommandLine(SimpleTestCase):
25552557
def test_program_name_from_argv(self):
25562558
"""

tests/test_runner/test_debug_sql.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
import unittest
34
from io import StringIO
45
from time import time
@@ -183,6 +184,7 @@ def test_log_record_sql_extra_none(self):
183184
@unittest.skipUnless(
184185
connection.vendor == "sqlite", "Only run on sqlite so we can check output SQL."
185186
)
187+
@mock.patch.dict(os.environ, {"PYTHON_COLORS": "0"})
186188
class TestDebugSQL(unittest.TestCase):
187189
class PassingTest(TestCase):
188190
def runTest(self):

tests/test_utils/test_simpletestcase.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import unittest
23
from io import StringIO
34
from unittest import mock
@@ -19,6 +20,7 @@ def skipped_test(self):
1920
pass
2021

2122

23+
@mock.patch.dict(os.environ, {"PYTHON_COLORS": "0"})
2224
@mock.patch.object(ErrorTestCase, "_post_teardown")
2325
@mock.patch.object(ErrorTestCase, "_pre_setup")
2426
class DebugInvocationTests(SimpleTestCase):

0 commit comments

Comments
 (0)