Model initialisation issues running functional tests

View: New views
4 Messages — Rating Filter:   Alert me  

Model initialisation issues running functional tests

by James-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Model initialisation issues running functional tests

by Robert Forkel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

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

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


Re: Model initialisation issues running functional tests

by James-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks Robert!

http://trac.turbogears.org/ticket/2404

On Nov 6, 3:22 pm, Robert Forkel <xrotw...@...> wrote:
> > Does TG2 have a Trac for me to open a ticket?
>
> yes:http://trac.turbogears.org/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Model initialisation issues running functional tests

by James-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

On Nov 6, 3:39 pm, James <rent.lupin.r...@...> wrote:

> Thanks Robert!
>
> http://trac.turbogears.org/ticket/2404
>
> On Nov 6, 3:22 pm, Robert Forkel <xrotw...@...> wrote:
>
> > > Does TG2 have a Trac for me to open a ticket?
>
> > yes:http://trac.turbogears.org/
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---