sqlalchemy - Python nose unit tests generating too many clients already -


i'm using python 3.3, pyramid, sqlalchemy, psygopg2. i'm using test postgres db unit tests. have 101 unit tests set nose run. on test 101 get:

nose.proxy.operationalerror: (operationalerror) fatal: sorry, many clients already

it seems traceback exception being thrown in

......./venv/lib/python3.3/site-packages/sqlalchemy-0.8.2-py3.3.egg/sqlalchemy/pool.py", line 368, in __connect

   connection = self.__pool._creator() 

perhaps teardown() not running after each test? isn't connection pool limit postgresql 100 @ 1 time?

here's basetest class:

class basetest(object):     def setup(self):         self.request = testing.dummyrequest()         self.config = testing.setup(request=self.request)         self.config.scan('../models')         sqlalchemy_url = 'postgresql://<user>:<pass>@localhost:5432/<db>'         engine = create_engine(sqlalchemy_url)         dbsession = scoped_session(sessionmaker(extension=zopetransactionextension()))         dbsession.configure(bind=engine)         base.metadata.bind = engine         base.metadata.create_all(engine)         self.dbsession = dbsession      def teardown(self):         testing.teardown() 

my test classes inherit basetest:

class testuser(basetest):     def __init__(self, dbsession = none):         if dbsession:             self.dbsession = dbsession      def test_create_user(self):         ......         ...... 

one of test classes tests many-to-many relationship, in test class first create records needed satisfy foreign key relationships:

from tests.test_user import testuser tests.test_app import testapp class testappuser(basetest):     def __init__(self, dbsession = none):         if dbsession:             self.dbsession = dbsession      def create_app_user(self):         test_app = testapp(self.dbsession)         test_user = testuser(self.dbsession)         test_app.request = testing.dummyrequest()         test_user.request = testing.dummyrequest()         app = test_app.create_app()         user = test_user.create_user()         ...... 

i'm passing dbsession testapp , testuser classes...i'm thinking source of problem, i'm not sure.

any appreciated. thanks.

pyramid has nothing sqlalchemy. there in pyramid's api link of sqlalchemy configuration in way pyramid care. therefore, pyramid's testing.teardown() not connections. how it? doesn't know exist.

you're using scoped sessions unit test, doesn't make lot of sense because unit tests not threaded. you're creating threadlocal sessions , not cleaning them up. aren't garbage collected because they're threadlocal. aren't manually closing connections connection pool thinks they're still being used.

is there reason need zopetransactionextension in tests? using transaction package in tests, or pyramid_tm? in test if don't know shouldn't there. you're calling create_all() setup() method? that's going slow hell introspecting database , creating tables on every request. ouch.

class basetest(object):     def setup(self):         self.request = testing.dummyrequest()         self.config = testing.setup(request=self.request)         self.config.scan('../models')         sqlalchemy_url = 'postgresql://<user>:<pass>@localhost:5432/<db>'         self.engine = create_engine(sqlalchemy_url)         base.metadata.create_all(bind=self.engine)         self.sessionmaker = sessionmaker(bind=self.engine)         self.sessions = []      def makesession(self, autoclose=true):         session = self.sessionmaker()         if autoclose:             self.sessions.append(session)      def teardown(self):         session in self.sessions:             session.close()         self.engine.dispose()         testing.teardown() 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -