[New-bugs-announce] [issue15836] unittest assertRaises should verify excClass is actually a BaseException class
report at bugs.python.org
Sat Sep 1 02:26:01 CEST 2012
New submission from Daniel Wagner-Hall:
The following code in a unittest test is a no-op:
I would expect this to fail the test, because I naively assumed omitting the exception class would act as:
self.assertRaises(BaseException, lambda: 1)
verifying that *any* Exception is raised.
I believe the correct behaviour is to raise a TypeError if excClass is not a BaseException-derived type, similar to if a non-type is passed as the first arg to issubclass.
Attached is a patch to do so. It also removes a no-op self.assertRaises from libimport's tests (because it started failing when I ran the tests with the patch). That assertion is redundant, because the two lines above perform the assertion being attempted.
title: unittest assertRaises should verify excClass is actually a BaseException class
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file27079/assertRaises.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce