Dear List.... 

I have a tg2.3 application with multiple (+300, and counting) working tests 
in place.

The `TestController` generated by quickstart provides a perfectly sound 
methodology for testing the full stack.  And, quite correctly, the 
TestController's setup/teardown does just that -- it creates/destroys the 
application environment and the entire database each time and calls 
websetup/ and subsequently all of its bootstrapped data.  (I'm using 
postgres and many of the model objects use postgres specific field types eg 
ranges -- consequently I'm unable to use an in-memory sqlite for the test 
env and any speed improvements that that would bring)

class MyTestController(TestController):
    def test_a(self):
       ...
    def test_b(self):
       ...

As per the above, by ('naively') sub-classing `TestController`, for each 
test method it contains, the entire application gets setup/torn down and 
this starts to get rather time-consuming... 

I should quickly add here that I'm entirely aware that for the purist, 
'testing methodology' requires a clean slate each time -- for my purposes, 
however, I'm comfortable that a dozen or so json callbacks in a 
sub-controller do not require the entire stack to be set up each time.  So, 
to try to speed this up, I have a boilerplate test module which looks as 
follows:

from myproject.tests import load_app, setup_app, setup_db, teardown_db
from myproject import model

app = None
environ = {'REMOTE_USER': 'X'}

def setup():
    global app
    app = load_app('main_without_authn')
    setup_app()

def teardown():
    model.DBSession.remove()
    teardown_db()

def test_a():
    resp = app.get('/a/aa', extra_environ=environ)
    ok_()

def test_b():
    resp = app.get('/b/bb', extra_environ=environ)
    ok_()

The methodology above works absolutely fine for my purposes: once per 
module, the 'app' and the database get set up and the static/test data 
required for my tests gets bootstrapped. (so far, so good...)

In order to try and refine this further, I'm trying to use nosetests' 
"package-level setup". (as per 
http://nose.readthedocs.org/en/latest/writing_tests.html). 
In a nutshell, the setup/teardown would be done in the __init__ and each 
module would "from . import app", ie something like:

__init__.py
--------------

app = None

def setup():
    global app
    app = load_app('main_without_authn')
    setup_app()

def teardown():
    model.DBSession.remove()
    teardown_db()

test_mod_1.py
--------------- 

from . import app

def test_a():
    resp = app.get('/a/aa', extra_environ=environ)
    ok_()

The problem with this is that I get:
     resp = app.get(....)
AttributeError: 'NoneType' object has no attribute 'get'

In other words, it seems that I'm unable to successfully hang onto 
'app'.... 

Can anyone out there suggest how this might be done??

Many thanks,
Rob 

(I've just noticed this exchange from some time ago in this mailing list:
https://groups.google.com/forum/#!searchin/turbogears/test/turbogears/JWEI06zzsh8/KHGY11EASYEJ
But it seems to deal with module-level tests rather than one level up... )

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply via email to