On Aug 5, 2006, at 3:16 AM, Jorge Vargas wrote:

On 8/4/06, Alberto Valverde <[EMAIL PROTECTED]> wrote:

On Aug 4, 2006, at 7:46 AM, Jorge Vargas wrote:

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)

I saw a couple of examples like that but I wanted to use nose-style tests for everything. I guess I'll have to use plain old TestCase classes.


maybe nose should implemente a set of module level functions that mimic the TestCase methods, I'll look around their trac to open a ticket/submit a patch.

Maybe the attached hack helps. Just make sure you don't keep it inside the path nosetests scans or it will spew a funky TypeError when trying to load the module when looking for tests in it. 

To use:

from TestCaseMod import *

test_foo():
failUnlessRaises(NotImplementedError, source.create)

Disclaimer: 
Minimally tested (sic)

HTH,
Alberto

Attachment: TestCaseMod.py.gz
Description: GNU Zip compressed data

Reply via email to