[issue4444] unittest - use contexts to assert exceptions

David Leonard report at bugs.python.org
Thu Nov 27 10:50:00 CET 2008


New submission from David Leonard <d+python at adaptive-enterprises.com>:

Patch to allow unit tests to test for exceptions through a 'with' 
statement. Resulting (failing) test would look like this:

  import unittest

  class T(unittest.TestCase):
     def runTest(self):
        with self.assertRaises(KeyError):
           raise ValueError

This saves having to put exception raising tests into a try/except 
block, which is cool. And by cool I mean totally sweet.

----------
components: Library (Lib)
files: unittest.patch
keywords: patch
messages: 76492
nosy: dleonard0
severity: normal
status: open
title: unittest - use contexts to assert exceptions
type: feature request
versions: Python 3.0
Added file: http://bugs.python.org/file12138/unittest.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4444>
_______________________________________


More information about the Python-bugs-list mailing list