Problem with Unittest:

Fredrik Lundh fredrik at pythonware.com
Tue May 13 11:15:43 EDT 2003


Frithiof Andreas Jensen wrote:

> I am trying to test some software using unittest with Python 2.2.2 (#37, Oct
> 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32 and I am having some
> problems with exceptions:
>
> The simple test script below yields:
>
> E
> ======================================================================
> ERROR: test_duffer (__main__.dufferTest)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "C:\tedfrje\traders_toolkit\test_duffer.py", line 12, in test_duffer
>     self.assertRaises(ValueError(), duffer())
>   File "C:\tedfrje\traders_toolkit\test_duffer.py", line 7, in duffer
>     raise ValueError()
> ValueError
>
> ----------------------------------------------------------------------
> Ran 1 tests in 0.010s
>
> FAILED (errors=1)
>
> In my opinion, the script should PASS because I specified that a
> ValueError() was the PASS criteria.
>
> What am I doing wrong?

assertRaises takes an exception *class* and a callable object
(usually a function or method).

you're passing in an exception instance and the *result* of your
duffer function.

getting rid of the extra parens fixes the problem:

        self.assertRaises(ValueError, duffer)

</F>








More information about the Python-list mailing list