unittest weirdness

Ethan Furman ethan at stoneleaf.us
Wed Mar 12 11:03:24 CET 2014


On 03/11/2014 08:36 PM, Terry Reedy wrote:
> On 3/11/2014 6:13 PM, John Gordon wrote:
>> In <mailman.8062.1394573210.18130.python-list at python.org> Ethan Furman <ethan at stoneleaf.us> writes:
>>
>>>           if missing:
>>>               raise ValueError('invoices %r missing from batch' % missing)
>>
>> It's been a while since I wrote test cases, but I recall using the assert*
>> methods (assertEqual, assertTrue, etc.) instead of raising exceptions.
>> Perhaps that's the issue?
>
> Yes. I believe the methods all raise AssertionError on failure, and the test methods are wrapped with try:.. except
> AssertionError as err:
>
>     if missing:
>       raise ValueError('invoices %r missing from batch' % missing)
>
> should be "assertEqual(missing, [], 'invoices missing from batch')" and if that fails, the non-empty list is printed
> along with the message.

I've tried it both ways, and both ways my process is being killed, presumably by the O/S.

I will say it's an extra motivating factor to have few failing tests -- if more than two of my tests fail, all I see are 
'.'s, 'E's, and 'F's, with no clues as to which test failed nor why.  Thank goodness for '-v' and being able to specify 
which method of which class to run!

--
~Ethan~



More information about the Python-list mailing list