[New-bugs-announce] [issue15836] unittest assertRaises should verify excClass is actually a BaseException class

Daniel Wagner-Hall 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:

self.assertRaises(lambda: 1)

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.

----------
components: Tests
files: assertRaises.patch
keywords: patch
messages: 169596
nosy: illicitonion
priority: normal
severity: normal
status: open
title: unittest assertRaises should verify excClass is actually a BaseException class
type: behavior
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>
<http://bugs.python.org/issue15836>
_______________________________________


More information about the New-bugs-announce mailing list