Michael Bayer wrote:
How do people get around this? What's best practice in this area?
your test suite ideally wouldn't be tearing down and building up tables many times.
Correct ;-)
For an application where the testing is against a fixed set of tables (i.e.
not at all like SQLA's own unit tests), you would run all your tests in
transactions that get rolled back when the test is complete.
This may show my poor RDB knowledge; if you need to test selects against
stuff that would have normally been committed to the DB, can you do that
without committing a transaction?
I use setup/teardowns like this for this purpose (assume scoped_session, which
yes you should probably use all the time so that the session is accessed by a
single reference):
Where do you actually drop/create the tables?
def setup_for_rollback():
Session.remove()
The docs on this are a little brief ;-)
http://www.sqlalchemy.org/docs/reference/orm/sessions.html#sqlalchemy.orm.scoping.ScopedSession.remove
This seems key to your suggested strategy. What does it do?
sess = Session()
c = sess.bind.connect()
global transaction
Maybe set as an attibute of a TestCase rather than asa global?
transaction = c.begin()
sess.bind = c
def teardown_for_rollback():
transaction.rollback()
Session.remove()
above, "transaction" is the "real" transaction. All begin/commits inside don't actually commit anything.
Again, this last bit escapes me, how come Session().commit() or begin
doesn't do anything?
cheers,
Chris
--
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.