On Fri, Aug 28, 2009 at 7:03 PM, Jason S.<[email protected]> wrote:
>
> I recently noticed that nose tests were failing with an error saying
> that some models had already been created. Turns out that since the
> appname/tests/__init__.py that paster creates executes a setup-app
> command in the same process as it loads the app, things get
> initialized twice. Models defined in init_model are affected, as are
> AuthKit's models if you are using the SQLAlchemy back end.
>
> I can hackishly set and check a global flag in init_model, but that
> seems wrong and doesn't help with AuthKit. I can take the setup-app
> line out, which works fine but I suppose could interfere with using
> fixtures later? Anyone else had this problem?
I create my tables in the test setup with dummy data, and drop then in
the teardown. I don't have anything in websetup. Websetup is really
only useful if you're distributing a public application or if all your
developers need to create their own databases. But in a real
situation you probably have existing data so you only create the
tables once and then copy them around.
I haven't looked at AuthKit so I don't know what kind of
initialization it needs.
My structure looks something like this:
myapp/tests/__init__.py
class BaseTestCase(unittest.TestCase):
tables = [] # Table objects used by the subclass tests.
base_tables = [model.auth.t_user] # Auth tables are always used.
def __init__(self):
# Some code copied from the default ControllerTestCase
def setUp(self):
for table in self.tables + self.base_tables:
table.drop(bind=meta.engine, checkfiirst=True)
table.create(bind=meta.engine)
self.populate_tables() # Defined in subclass.
self.populate_base_tables()
def tearDown(self):
for table in self.tables:
table.drop(bind=meta.engine)
This is an app with several parts using different tables, with each
part having a different model module and test module. You can make it
simpler if all tests use the same tables. This also recreates the
tables with the same data for every test. I did not find the overhead
significant. But if some test classes don't use tables, you can have
a flag for that.
--
Mike Orr <[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---