[Python-checkins] cpython (2.7): Modernize unittest example

raymond.hettinger python-checkins at python.org
Fri Mar 22 15:17:50 CET 2013


http://hg.python.org/cpython/rev/d6336b2e4db6
changeset:   82877:d6336b2e4db6
branch:      2.7
parent:      82872:66e30c4870bb
user:        Raymond Hettinger <python at rcn.com>
date:        Fri Mar 22 07:17:38 2013 -0700
summary:
  Modernize unittest example

files:
  Doc/tutorial/stdlib.rst |  6 ++++--
  1 files changed, 4 insertions(+), 2 deletions(-)


diff --git a/Doc/tutorial/stdlib.rst b/Doc/tutorial/stdlib.rst
--- a/Doc/tutorial/stdlib.rst
+++ b/Doc/tutorial/stdlib.rst
@@ -278,8 +278,10 @@
        def test_average(self):
            self.assertEqual(average([20, 30, 70]), 40.0)
            self.assertEqual(round(average([1, 5, 7]), 1), 4.3)
-           self.assertRaises(ZeroDivisionError, average, [])
-           self.assertRaises(TypeError, average, 20, 30, 70)
+           with self.assertRaises(ZeroDivisionError):
+               average([])
+           with self.assertRaises(TypeError):
+               average(20, 30, 70)
 
    unittest.main() # Calling from the command line invokes all tests
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list