Model initialisation issues running functional tests

2 views
Skip to first unread message

James

unread,
Nov 6, 2009, 10:16:49 AM11/6/09
to TurboGears
Hello all, this is related to this "functional tests in tg2" thread:
http://groups.google.com/group/turbogears/t/56185a76d26e37d7.

I've recreated the issues described there in a near-virgin TG2
install, so it does seem there's something amiss with model
initialisation in the test scaffolding, rather than in our own code.

To reproduce:
Create a new virtualenv with tg2-bootstrap.py
quickstart a TG2 project
Add a method to the root controller which interacts with the DB. E.g.:
@expose()
def change_name(self, name):
usr = model.User.by_user_name('manager')
usr.display_name = name
return {}
Add two functional tests to TestRootController in test_root.py. E.g.:
def test_a(self):
rsp = self.app.get('/change_name/dave', status=200)
usr = model.User.by_user_name('manager')
assert_equals(usr.display_name, 'dave')
def test_b(self):
rsp = self.app.get('/change_name/bob', status=200)
usr = model.User.by_user_name('manager')
assert_equals(usr.display_name, 'bob')

Run nosetests and wait for the "no such table" errors.

Does anyone have suggestions on what might be causing this? What extra
information would help debug this?

Does TG2 have a Trac for me to open a ticket?

Thanks!
James

Robert Forkel

unread,
Nov 6, 2009, 10:22:49 AM11/6/09
to turbo...@googlegroups.com
>
> Does TG2 have a Trac for me to open a ticket?

yes:
http://trac.turbogears.org/

James

unread,
Nov 6, 2009, 10:39:01 AM11/6/09
to TurboGears

James

unread,
Nov 11, 2009, 12:16:01 PM11/11/09
to TurboGears
OK, I have some more information on this problem which I'll append to
the Trac ticket.

It seems that different SQLAlchemy engines are being used during the
set up and running phases of my second test.

I asked on the SQLAlchemy list, and the advice was that there should
only ever be one engine (i.e. one call to create_engine). However, I
assume that the multiple calls TG2 makes is symptomatic of wanting a
completely blank slate for each test method.

The problem is in running the second test method, when a new engine is
created and used for creating the model tables, but the *first* test
method's (now empty) engine is used while running the actual test.

Basically, it seems that the original engine is persisted somewhere,
and is resurrected when issuing normal (non-DDL) SQL in websetup.py.
model.metadata.create_all uses the newly created engine because it is
passed in explictly as the bind. Invoking DBSession.configure
(bind=my_new_engine) does not seem to update the engine in use by the
ORM.

At this point, it would be really useful if someone more familiar with
the guts of TG2 could take a look at this and give me some pointers...
There seems to be two possible fixes: get SQLAlchemy to realise we've
moved on to a new engine, or only use one engine throughout an entire
TG2 test suite, as SQLAlchemy expects.

I've created a github project here: http://github.com/goodgravy/tg2-broken
which recreates the bug - it's a new TG2 application, with the three
extra methods described above.

James
Reply all
Reply to author
Forward
0 new messages