Hi,
New with sqlalchemy, i'm trying to unittest my code:
import unittest
import os
from sqlalchemy.orm.exc import NoResultFound
import User
SQLITE_FILE = 'test.db'
class UserAddTestCase(unittest.TestCase):
def setUp(self):
... some code which create the session (removed to be clearer)
self.session is stored
def tearDown(self):
if os.path.exists(self.testfile ):
os.remove(self.testfile )
def test_add_user(self):
user1 = User('user1_fn', 'user1_sn')
self.session.add(user1)
self.assertEqual(self.session.query(User).count(), 1)
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())
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.