On Aug 4, 2006, at 7:46 AM, 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

Hi, if using a unittest.TestCase subclass for your tests (like TG's DBTest) you can use the failUnlessRaises method.

class TestMyApp(TestCase):
def test_int(self):
""" test that int("a") raises a ValueError """ 
self.failUnlessRaises(ValueError, int, "a")
# As in your example:
def test_create(self):
self.failUnlessRaises(NotImplementedError, source.create)

HTH,
Alberto

--~--~---------~--~----~------------~-------~--~----~
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