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
)



> if __name__ == '__main__':
>    unittest.main()
> 
> The output is:
> 
> ======================================================================
> ERROR: test_add_user (__main__.UserAddTestCase)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "models.py", line 30, in test_add_user
>    self.assertRaises(NoResultFound,
> self.session.query(User).filter(User.firstname == "other_fn").one())
>  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.5-
> py2.6.egg/sqlalchemy/orm/query.py", line 1651, in one
>    raise orm_exc.NoResultFound("No row was found for one()")
> NoResultFound: No row was found for one()
> 
> ----------------------------------------------------------------------
> Ran 1 test in 0.234s
> 
> FAILED (errors=1)
> 
> My code is supposed to raise a NoResultFound exception which is ok but
> the assertRaises does not catch it and my test fails but should be a
> success...
> 
> Anyone could explain me ?
> 
> thanks a lot
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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