[TIP] RFC: Post-assertRaises assertions WAS: ANN: unittest2 0.4.0 Release

Olemis Lang olemis at gmail.com
Fri Apr 9 09:34:50 PDT 2010


On Fri, Apr 9, 2010 at 11:27 AM, Michael Foord
<fuzzyman at voidspace.org.uk> wrote:
> On 09/04/2010 14:55, Olemis Lang wrote:
>>
>> On Fri, Apr 9, 2010 at 8:15 AM, Michael Foord<fuzzyman at voidspace.org.uk>
>>  wrote:
>>
>>>
>>> On 09/04/2010 14:10, Olemis Lang wrote:
>>>
>>>>
>>>> On Thu, Apr 8, 2010 at 5:42 PM, Michael Foord<michael at voidspace.org.uk>
>>>>  wrote:
>>>>
>>>>
>>>>>
>>>>> Hello all,
>>>>>
>>>>
>>>> :o)
>>>>
>>>>
>>>>>
>>>>> I'm pleased to announce the release of version 0.4.0 of unittest2.
>>>>>
>>>>
>>>> [...]
>>>>
>>>>
>>>>>
>>>>> For full details of all the new features, see my blog entry:
>>>>>
>>>>> *
>>>>>
>>>>> http://www.voidspace.org.uk/python/weblog/arch_d7_2010_04_03.shtml#e1171
>>>>>
>>>>>
>>>>
>>>> I wanted to know if you have considered support for writing assertions
>>>> targeting the exception object been raised . In my experience that is
>>>> very helpful when testing some kind of systems. For instance, in Trac
>>>> XmlRpcPlugin (<=0.1.6, current trunk ;o) you can find many tests
>>>> (actually all TCs checking for error conditions ;o) like this
>>>>
>>>
>>> Did you check the docs?
>>>
>>>
>>
>> Good RTFM , thnx . Should be something like this (isn't it ?):
>>
>> {{{
>> #!python
>>
>> # blah blah blah ...
>>    def test_wrong_argspec(self):
>>        ctx = self.assertRaises(xmlrpclib.Fault)
>>        with ctx :
>>            self.admin.system.listMethods("hello")
>>            self.fail("Oops. Wrong argspec accepted???")
>>        e = ctx.exception
>>        self.assertEquals(1, e.faultCode)
>>        self.assertTrue("listMethods() takes exactly 2 arguments" \
>>                                    in e.faultString)
>> }}}
>>
>> However I'm also interested in how it works (backwards compatibility
>> ;o) for versions with no support for context managers (AFAIK, there
>> are still people using Trac on Py 2.4 ;o)
>>
>> Is it possible to consider returning the exception object when the
>> ctxman is not returned ?
>>
>
> No, sorry. There is no need for this in Python 2.7 (which has context
> managers) and I'm not going to put incompatible changes into unittest2.
>

FWIW, since assertRaises doesn't return anything then all code using
that method today would be backwards compatible (they all ignore its
return value which is always None ;o) ... I know you already said *NO*
.

back to my cave ...

> You can still use the alternative version of assertRaises if you *just* want
> to check the exception message.
>

ok

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:



More information about the testing-in-python mailing list