summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>2024-12-05 19:10:46 (GMT)
committerGitHub <noreply@github.com>2024-12-05 19:10:46 (GMT)
commit23f2e8f13c4e4a34106cf96fad9329cbfbf8844d (patch)
treea2f306c0ccd6c05302f4bb5eb279e3f0f6834a65 /Lib/test
parentd958d9f4a1b71c6d30960bf6c53c41046ea94590 (diff)
downloadcpython-23f2e8f13c4e4a34106cf96fad9329cbfbf8844d.zip
cpython-23f2e8f13c4e4a34106cf96fad9329cbfbf8844d.tar.gz
cpython-23f2e8f13c4e4a34106cf96fad9329cbfbf8844d.tar.bz2
gh-127221: Add colour to unittest output (#127223)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_unittest/test_async_case.py2
-rw-r--r--Lib/test/test_unittest/test_program.py6
-rw-r--r--Lib/test/test_unittest/test_result.py16
-rw-r--r--Lib/test/test_unittest/test_runner.py13
-rw-r--r--Lib/test/test_unittest/test_skipping.py3
5 files changed, 39 insertions, 1 deletions
diff --git a/Lib/test/test_unittest/test_async_case.py b/Lib/test/test_unittest/test_async_case.py
index 00ef55b..8ea244b 100644
--- a/Lib/test/test_unittest/test_async_case.py
+++ b/Lib/test/test_unittest/test_async_case.py
@@ -2,6 +2,7 @@ import asyncio
import contextvars
import unittest
from test import support
+from test.support import force_not_colorized
support.requires_working_socket(module=True)
@@ -252,6 +253,7 @@ class TestAsyncCase(unittest.TestCase):
test.doCleanups()
self.assertEqual(events, ['asyncSetUp', 'test', 'asyncTearDown', 'cleanup'])
+ @force_not_colorized
def test_exception_in_tear_clean_up(self):
class Test(unittest.IsolatedAsyncioTestCase):
async def asyncSetUp(self):
diff --git a/Lib/test/test_unittest/test_program.py b/Lib/test/test_unittest/test_program.py
index 7241cf5..0b46f33 100644
--- a/Lib/test/test_unittest/test_program.py
+++ b/Lib/test/test_unittest/test_program.py
@@ -4,6 +4,7 @@ import subprocess
from test import support
import unittest
import test.test_unittest
+from test.support import force_not_colorized
from test.test_unittest.test_result import BufferedWriter
@@ -120,6 +121,7 @@ class Test_TestProgram(unittest.TestCase):
self.assertEqual(['test.test_unittest', 'test.test_unittest2'],
program.testNames)
+ @force_not_colorized
def test_NonExit(self):
stream = BufferedWriter()
program = unittest.main(exit=False,
@@ -135,6 +137,7 @@ class Test_TestProgram(unittest.TestCase):
'expected failures=1, unexpected successes=1)\n')
self.assertTrue(out.endswith(expected))
+ @force_not_colorized
def test_Exit(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit) as cm:
@@ -152,6 +155,7 @@ class Test_TestProgram(unittest.TestCase):
'expected failures=1, unexpected successes=1)\n')
self.assertTrue(out.endswith(expected))
+ @force_not_colorized
def test_ExitAsDefault(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit):
@@ -167,6 +171,7 @@ class Test_TestProgram(unittest.TestCase):
'expected failures=1, unexpected successes=1)\n')
self.assertTrue(out.endswith(expected))
+ @force_not_colorized
def test_ExitSkippedSuite(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit) as cm:
@@ -179,6 +184,7 @@ class Test_TestProgram(unittest.TestCase):
expected = '\n\nOK (skipped=1)\n'
self.assertTrue(out.endswith(expected))
+ @force_not_colorized
def test_ExitEmptySuite(self):
stream = BufferedWriter()
with self.assertRaises(SystemExit) as cm:
diff --git a/Lib/test/test_unittest/test_result.py b/Lib/test/test_unittest/test_result.py
index 4e5ec54..746b9fa 100644
--- a/Lib/test/test_unittest/test_result.py
+++ b/Lib/test/test_unittest/test_result.py
@@ -7,6 +7,7 @@ from test.support import warnings_helper, captured_stdout
import traceback
import unittest
from unittest.util import strclass
+from test.support import force_not_colorized
from test.test_unittest.support import BufferedWriter
@@ -14,7 +15,7 @@ class MockTraceback(object):
class TracebackException:
def __init__(self, *args, **kwargs):
self.capture_locals = kwargs.get('capture_locals', False)
- def format(self):
+ def format(self, **kwargs):
result = ['A traceback']
if self.capture_locals:
result.append('locals')
@@ -205,6 +206,7 @@ class Test_TestResult(unittest.TestCase):
self.assertIs(test_case, test)
self.assertIsInstance(formatted_exc, str)
+ @force_not_colorized
def test_addFailure_filter_traceback_frames(self):
class Foo(unittest.TestCase):
def test_1(self):
@@ -231,6 +233,7 @@ class Test_TestResult(unittest.TestCase):
self.assertEqual(len(dropped), 1)
self.assertIn("raise self.failureException(msg)", dropped[0])
+ @force_not_colorized
def test_addFailure_filter_traceback_frames_context(self):
class Foo(unittest.TestCase):
def test_1(self):
@@ -260,6 +263,7 @@ class Test_TestResult(unittest.TestCase):
self.assertEqual(len(dropped), 1)
self.assertIn("raise self.failureException(msg)", dropped[0])
+ @force_not_colorized
def test_addFailure_filter_traceback_frames_chained_exception_self_loop(self):
class Foo(unittest.TestCase):
def test_1(self):
@@ -285,6 +289,7 @@ class Test_TestResult(unittest.TestCase):
formatted_exc = result.failures[0][1]
self.assertEqual(formatted_exc.count("Exception: Loop\n"), 1)
+ @force_not_colorized
def test_addFailure_filter_traceback_frames_chained_exception_cycle(self):
class Foo(unittest.TestCase):
def test_1(self):
@@ -446,6 +451,7 @@ class Test_TestResult(unittest.TestCase):
result.addUnexpectedSuccess(None)
self.assertTrue(result.shouldStop)
+ @force_not_colorized
def testFailFastSetByRunner(self):
stream = BufferedWriter()
runner = unittest.TextTestRunner(stream=stream, failfast=True)
@@ -619,6 +625,7 @@ class Test_TextTestResult(unittest.TestCase):
test.run(result)
return stream.getvalue()
+ @force_not_colorized
def testDotsOutput(self):
self.assertEqual(self._run_test('testSuccess', 1), '.')
self.assertEqual(self._run_test('testSkip', 1), 's')
@@ -627,6 +634,7 @@ class Test_TextTestResult(unittest.TestCase):
self.assertEqual(self._run_test('testExpectedFailure', 1), 'x')
self.assertEqual(self._run_test('testUnexpectedSuccess', 1), 'u')
+ @force_not_colorized
def testLongOutput(self):
classname = f'{__name__}.{self.Test.__qualname__}'
self.assertEqual(self._run_test('testSuccess', 2),
@@ -642,17 +650,21 @@ class Test_TextTestResult(unittest.TestCase):
self.assertEqual(self._run_test('testUnexpectedSuccess', 2),
f'testUnexpectedSuccess ({classname}.testUnexpectedSuccess) ... unexpected success\n')
+ @force_not_colorized
def testDotsOutputSubTestSuccess(self):
self.assertEqual(self._run_test('testSubTestSuccess', 1), '.')
+ @force_not_colorized
def testLongOutputSubTestSuccess(self):
classname = f'{__name__}.{self.Test.__qualname__}'
self.assertEqual(self._run_test('testSubTestSuccess', 2),
f'testSubTestSuccess ({classname}.testSubTestSuccess) ... ok\n')
+ @force_not_colorized
def testDotsOutputSubTestMixed(self):
self.assertEqual(self._run_test('testSubTestMixed', 1), 'sFE')
+ @force_not_colorized
def testLongOutputSubTestMixed(self):
classname = f'{__name__}.{self.Test.__qualname__}'
self.assertEqual(self._run_test('testSubTestMixed', 2),
@@ -661,6 +673,7 @@ class Test_TextTestResult(unittest.TestCase):
f' testSubTestMixed ({classname}.testSubTestMixed) [fail] (c=3) ... FAIL\n'
f' testSubTestMixed ({classname}.testSubTestMixed) [error] (d=4) ... ERROR\n')
+ @force_not_colorized
def testDotsOutputTearDownFail(self):
out = self._run_test('testSuccess', 1, AssertionError('fail'))
self.assertEqual(out, 'F')
@@ -671,6 +684,7 @@ class Test_TextTestResult(unittest.TestCase):
out = self._run_test('testSkip', 1, AssertionError('fail'))
self.assertEqual(out, 'sF')
+ @force_not_colorized
def testLongOutputTearDownFail(self):
classname = f'{__name__}.{self.Test.__qualname__}'
out = self._run_test('testSuccess', 2, AssertionError('fail'))
diff --git a/Lib/test/test_unittest/test_runner.py b/Lib/test/test_unittest/test_runner.py
index 1b9cef4..1131cd7 100644
--- a/Lib/test/test_unittest/test_runner.py
+++ b/Lib/test/test_unittest/test_runner.py
@@ -4,6 +4,7 @@ import sys
import pickle
import subprocess
from test import support
+from test.support import force_not_colorized
import unittest
from unittest.case import _Outcome
@@ -106,6 +107,7 @@ class TestCleanUp(unittest.TestCase):
self.assertTrue(test.doCleanups())
self.assertEqual(cleanups, [(2, (), {}), (1, (1, 2, 3), dict(four='hello', five='goodbye'))])
+ @force_not_colorized
def testCleanUpWithErrors(self):
class TestableTest(unittest.TestCase):
def testNothing(self):
@@ -416,6 +418,7 @@ class TestClassCleanup(unittest.TestCase):
self.assertIsInstance(e2[1], CustomError)
self.assertEqual(str(e2[1]), 'cleanup1')
+ @force_not_colorized
def test_with_errors_addCleanUp(self):
ordering = []
class TestableTest(unittest.TestCase):
@@ -439,6 +442,7 @@ class TestClassCleanup(unittest.TestCase):
['setUpClass', 'setUp', 'cleanup_exc',
'tearDownClass', 'cleanup_good'])
+ @force_not_colorized
def test_run_with_errors_addClassCleanUp(self):
ordering = []
class TestableTest(unittest.TestCase):
@@ -462,6 +466,7 @@ class TestClassCleanup(unittest.TestCase):
['setUpClass', 'setUp', 'test', 'cleanup_good',
'tearDownClass', 'cleanup_exc'])
+ @force_not_colorized
def test_with_errors_in_addClassCleanup_and_setUps(self):
ordering = []
class_blow_up = False
@@ -514,6 +519,7 @@ class TestClassCleanup(unittest.TestCase):
['setUpClass', 'setUp', 'tearDownClass',
'cleanup_exc'])
+ @force_not_colorized
def test_with_errors_in_tearDownClass(self):
ordering = []
class TestableTest(unittest.TestCase):
@@ -590,6 +596,7 @@ class TestClassCleanup(unittest.TestCase):
'inner setup', 'inner test', 'inner cleanup',
'end outer test', 'outer cleanup'])
+ @force_not_colorized
def test_run_empty_suite_error_message(self):
class EmptyTest(unittest.TestCase):
pass
@@ -663,6 +670,7 @@ class TestModuleCleanUp(unittest.TestCase):
self.assertEqual(cleanups,
[((1, 2), {'function': 'hello'})])
+ @force_not_colorized
def test_run_module_cleanUp(self):
blowUp = True
ordering = []
@@ -802,6 +810,7 @@ class TestModuleCleanUp(unittest.TestCase):
'tearDownClass', 'cleanup_good'])
self.assertEqual(unittest.case._module_cleanups, [])
+ @force_not_colorized
def test_run_module_cleanUp_when_teardown_exception(self):
ordering = []
class Module(object):
@@ -963,6 +972,7 @@ class TestModuleCleanUp(unittest.TestCase):
self.assertEqual(cleanups,
[((1, 2), {'function': 3, 'self': 4})])
+ @force_not_colorized
def test_with_errors_in_addClassCleanup(self):
ordering = []
@@ -996,6 +1006,7 @@ class TestModuleCleanUp(unittest.TestCase):
['setUpModule', 'setUpClass', 'test', 'tearDownClass',
'cleanup_exc', 'tearDownModule', 'cleanup_good'])
+ @force_not_colorized
def test_with_errors_in_addCleanup(self):
ordering = []
class Module(object):
@@ -1026,6 +1037,7 @@ class TestModuleCleanUp(unittest.TestCase):
['setUpModule', 'setUp', 'test', 'tearDown',
'cleanup_exc', 'tearDownModule', 'cleanup_good'])
+ @force_not_colorized
def test_with_errors_in_addModuleCleanup_and_setUps(self):
ordering = []
module_blow_up = False
@@ -1318,6 +1330,7 @@ class Test_TextTestRunner(unittest.TestCase):
expectedresult = (runner.stream, DESCRIPTIONS, VERBOSITY)
self.assertEqual(runner._makeResult(), expectedresult)
+ @force_not_colorized
@support.requires_subprocess()
def test_warnings(self):
"""
diff --git a/Lib/test/test_unittest/test_skipping.py b/Lib/test/test_unittest/test_skipping.py
index f146dca..f5cb860 100644
--- a/Lib/test/test_unittest/test_skipping.py
+++ b/Lib/test/test_unittest/test_skipping.py
@@ -1,5 +1,6 @@
import unittest
+from test.support import force_not_colorized
from test.test_unittest.support import LoggingResult
@@ -293,6 +294,7 @@ class Test_TestSkipping(unittest.TestCase):
self.assertFalse(result.unexpectedSuccesses)
self.assertTrue(result.wasSuccessful())
+ @force_not_colorized
def test_expected_failure_and_fail_in_cleanup(self):
class Foo(unittest.TestCase):
@unittest.expectedFailure
@@ -372,6 +374,7 @@ class Test_TestSkipping(unittest.TestCase):
self.assertEqual(result.unexpectedSuccesses, [test])
self.assertFalse(result.wasSuccessful())
+ @force_not_colorized
def test_unexpected_success_and_fail_in_cleanup(self):
class Foo(unittest.TestCase):
@unittest.expectedFailure