[Tutor] unittests, testing a type

Kent Johnson kent37 at tds.net
Tue Jul 14 16:18:32 CEST 2009

On Tue, Jul 14, 2009 at 9:45 AM, A.T.Hofkamp<a.t.hofkamp at tue.nl> wrote:
> Todd Matsumoto wrote:
>> Hi,
>> Does anyone know how to do a unittest assert for a type?

> For new-style classes, you should be able to do
> type(result) is Decimal

When possible, it's better to use assertEqual() rather than a plain
assert_() because you will get a better error message on failure.

If you write
  self.assert_(type(result) is Decimal)
on failure you will get an uninformative message like "assertion failed"

If you write
  self.assertEqual(type(result), Decimal)
you will get an error more like "float != Decimal"


More information about the Tutor mailing list