summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/test_runner.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2010-12-01 00:56:10 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2010-12-01 00:56:10 (GMT)
commit60901876561a4ef665555e38fae1bdfe7bda78ba (patch)
treee0f1998dfc9a106dbcef71a614e905bd475dd7db /Lib/unittest/test/test_runner.py
parent00f2f97dbd3db898e5d6c2368edc780a81e2e5fe (diff)
downloadcpython-60901876561a4ef665555e38fae1bdfe7bda78ba.zip
cpython-60901876561a4ef665555e38fae1bdfe7bda78ba.tar.gz
cpython-60901876561a4ef665555e38fae1bdfe7bda78ba.tar.bz2
#10535: Enable silenced warnings in unittest by default
Diffstat (limited to 'Lib/unittest/test/test_runner.py')
-rw-r--r--Lib/unittest/test/test_runner.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_runner.py b/Lib/unittest/test/test_runner.py
index 25f7541..efd4962 100644
--- a/Lib/unittest/test/test_runner.py
+++ b/Lib/unittest/test/test_runner.py
@@ -1,5 +1,8 @@
import io
+import os
+import sys
import pickle
+import subprocess
import unittest
@@ -144,6 +147,7 @@ class Test_TextTestRunner(unittest.TestCase):
self.assertFalse(runner.failfast)
self.assertFalse(runner.buffer)
self.assertEqual(runner.verbosity, 1)
+ self.assertEqual(runner.warnings, None)
self.assertTrue(runner.descriptions)
self.assertEqual(runner.resultclass, unittest.TextTestResult)
@@ -244,3 +248,57 @@ class Test_TextTestRunner(unittest.TestCase):
expectedresult = (runner.stream, DESCRIPTIONS, VERBOSITY)
self.assertEqual(runner._makeResult(), expectedresult)
+
+ def test_warnings(self):
+ """
+ Check that warnings argument of TextTestRunner correctly affects the
+ behavior of the warnings.
+ """
+ # see #10535 and the _test_warnings file for more information
+
+ def get_parse_out_err(p):
+ return [b.splitlines() for b in p.communicate()]
+ opts = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ cwd=os.path.dirname(__file__))
+ ae_msg = b'Please use assertEqual instead.'
+ at_msg = b'Please use assertTrue instead.'
+
+ # no args -> all the warnings are printed, unittest warnings only once
+ p = subprocess.Popen([sys.executable, '_test_warnings.py'], **opts)
+ out, err = get_parse_out_err(p)
+ self.assertEqual(err[-1], b'OK')
+ # check that the total number of warnings in the output is correct
+ self.assertEqual(len(out), 12)
+ # check that the numbers of the different kind of warnings is correct
+ for msg in [b'dw', b'iw', b'uw']:
+ self.assertEqual(out.count(msg), 3)
+ for msg in [ae_msg, at_msg, b'rw']:
+ self.assertEqual(out.count(msg), 1)
+
+ args_list = (
+ # passing 'ignore' as warnings arg -> no warnings
+ [sys.executable, '_test_warnings.py', 'ignore'],
+ # -W doesn't affect the result if the arg is passed
+ [sys.executable, '-Wa', '_test_warnings.py', 'ignore'],
+ # -W affects the result if the arg is not passed
+ [sys.executable, '-Wi', '_test_warnings.py']
+ )
+ # in all these cases no warnings are printed
+ for args in args_list:
+ p = subprocess.Popen(args, **opts)
+ out, err = get_parse_out_err(p)
+ self.assertEqual(err[-1], b'OK')
+ self.assertEqual(len(out), 0)
+
+
+ # passing 'always' as warnings arg -> all the warnings printed,
+ # unittest warnings only once
+ p = subprocess.Popen([sys.executable, '_test_warnings.py', 'always'],
+ **opts)
+ out, err = get_parse_out_err(p)
+ self.assertEqual(err[-1], b'OK')
+ self.assertEqual(len(out), 14)
+ for msg in [b'dw', b'iw', b'uw', b'rw']:
+ self.assertEqual(out.count(msg), 3)
+ for msg in [ae_msg, at_msg]:
+ self.assertEqual(out.count(msg), 1)