Hi folks I wasn't sure if this warranted a bug in the tracker, so I thought I'd raise it here first.
unittest has assertIn, assertNotIn, assertEqual, assertNotEqual and so on. So, it seems odd to me that there isn't assertNotRaises. Is there any particular motivation for not putting it in? I've attached a simple patch against Python 3's trunk to give an idea of what I have in mind. Thanks Wilfred
diff -r 84280fac98b9 Lib/unittest/case.py --- a/Lib/unittest/case.py Tue Sep 27 07:30:00 2011 +0200 +++ b/Lib/unittest/case.py Tue Sep 27 19:45:03 2011 +0100 @@ -542,6 +542,18 @@ except UnicodeDecodeError: return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg)) + def assertNotRaises(self, excClass, callableObj=None, *args, **kwargs): + """Fail if an exception of class excClass is thrown by + callableObj when invoked with arguments args and keyword + arguments kwargs. + + """ + try: + callableObj(*args, **kwargs) + except excClass: + raise self.failureException("%s was raised" % excClass) + + def assertRaises(self, excClass, callableObj=None, *args, **kwargs): """Fail unless an exception of class excClass is thrown by callableObj when invoked with arguments args and keyword
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com