Engine per test is v inefficient, are you at least calling dispose() on each one in teardown?
On Thursday, September 8, 2016, Iain Duncan <iainduncanli...@gmail.com> wrote: > Hi Jonathan, sure can, here it is below. I think maybe this has something > to do with the fact that we are creating a new engine and dropping the > schema on each pass maybe? Because it seems to *only* happen when we run > about 75 tests in a row. > > Thanks for looking! > > class FunctionalTestSuite(unittest.TestCase): > """ > base class for functional test suite with db seeding" > """ > > # derived class needs to set this to the package of the app under test > # IE app_module = examp.app > app_package = None > > # derived class needs to put settings in here > settings = { > 'sqlalchemy.url': None > } > > def __init__(self, *args, **kwargs): > super(FunctionalTestSuite, self).__init__(*args, **kwargs) > > @classmethod > def setUpClass(cls): > "class level setUp creates tables" > configure_mappers() > # separate session factory for our test runner > cls.engine = engine_from_config(cls.settings, prefix='sqlalchemy.') > cls.session_factory = sessionmaker(bind=cls.engine) > > @classmethod > def init_db(cls): > "initialize the database and create sessions, normally called from > setUp" > # drop and recreate tables once per test > # NB: this has to be done differently for postgres because it's a > constraint nazi > if 'postgres' in cls.settings['sqlalchemy.url']: > cls.engine.execute("drop owned by semaphore") > cls.engine.execute("create schema if not exists public") > else: > Base.metadata.drop_all(bind=cls.engine) > Base.metadata.create_all(bind=cls.engine) > > def init_sessions(self): > "init seed and confirm sessions, normally called from setUp" > # create sessions for seeding and separate for confirming > self.seed_dbs = self.session_factory() > self.confirm_dbs = self.session_factory() > > def init_app(self): > "init test wsgi app, normally called from setUp" > self.app = self.app_package.main({}, **self.settings) > self.testapp = webtest.TestApp(self.app) > > def setUp(self): > # for tests where we want fresh db on *every* test, we use this > self.init_db() > self.init_sessions() > self.init_app() > > def tearDown(self): > self.seed_dbs.close() > self.confirm_dbs.close() > > > On Wed, Sep 7, 2016 at 8:37 PM, Jonathan Vanasco <jvana...@gmail.com > <javascript:_e(%7B%7D,'cvml','jvana...@gmail.com');>> wrote: > >> can you share the test harness? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sqlalchemy+unsubscr...@googlegroups.com >> <javascript:_e(%7B%7D,'cvml','sqlalchemy%2bunsubscr...@googlegroups.com');> >> . >> To post to this group, send email to sqlalchemy@googlegroups.com >> <javascript:_e(%7B%7D,'cvml','sqlalchemy@googlegroups.com');>. >> Visit this group at https://groups.google.com/group/sqlalchemy. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com > <javascript:_e(%7B%7D,'cvml','sqlalchemy%2bunsubscr...@googlegroups.com');> > . > To post to this group, send email to sqlalchemy@googlegroups.com > <javascript:_e(%7B%7D,'cvml','sqlalchemy@googlegroups.com');>. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.