On Fri, 2006-08-04 at 01:46 -0400, Jorge Vargas wrote:
> Hi 
> 
> I have been reading about nose and I find it great.
> 
> I have been looking into TG's test and all exceptions related are like
> this, so say the exception name in the string but what if I must be
> sure that I get exception type X 
>     try:
>         w.name = "foo"
>         assert False, "should have gotten an exception"
>     except ValueError:
>         pass
> 
> I have this, but it will actually fail all the time, and since we
> don't have python 2.6 we can't use the try/catch/finally, so any
> suggestions on how to test for method foo to raise exception bar and
> fail the test if that doesn't happen?
> 
>     def test_create(self):
>         try:
>             source.create ()
>         except NotImplementedError:
>             assert True
>         assert False

py.test (from codespeak.net's svn) has py.test.raises.

i.e.

in test_simple.py::

import py.test

def inverse(x):
    return 1/x

def test_half():
    assert inverse(2.0) == 0.5

def test_raises():
    py.test.raises(ZeroDivisionError, inverse, 0.0)

def test_raises_string():
    py.test.raises(ZeroDivisionError, "1.0/0.0")

Surely nose has a similar feature?
-- 
Regards,
Stephen Thorne
Development Engineer


Scanned by the NetBox from NetBox Blue
(http://netboxblue.com/)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to