On 11/01/2011 15:26, Michael Bayer wrote:

On Jan 11, 2011, at 4:56 AM, pr64 wrote:


self.assertEqual(self.session.query(User).filter(User.firstname ==
"user1_fn").count(),  1)
        self.assertRaises(NoResultFound,
self.session.query(User).filter(User.firstname == "other_fn").one())


assertRaises receives a callable, which when called raises the expected error.  
 So you need to not actually invoke one():

self.assertRaises(NoResultFound,
                self.session.query(User).
                        filter(User.firstname == "other_fn").
                        one
)

Yeah, I find this pattern a bit clunky. Nowadays, context managers provide a much nicer way of doing these kinds of tests. Most testing packages have some flavour of this, my testfixtures package has ShouldRaise:

http://packages.python.org/testfixtures/exceptions.html#the-shouldraise-context-manager

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
           - http://www.simplistix.co.uk

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to