So I'm using the DropEverything recipe
(https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/DropEverything)
to reset a Postgres database before and after running unit tests. My setup
is essentially the following
(using SQLAlchemy version 1.0.13):
Base = declarative_base()
engine =
create_engine("postgresql+psycopg2://postgres:password@localhost/test_db",
pool_size=50, echo=False)
def AppTestCase(TestCase):
def __init__(self):
self.session = scoped_session(sessionmaker(bind=engine,
query_cls=Query))()
@classmethod
def setUpClass(cls):
reset_database() # calls DropEverything recipe using engine
(also used for all sessions), plus a call to
Base.metadata.create_all(engine)
cls._session = scoped_session(sessionmaker(bind=engine,
query_cls=Query))()
# Store some objects using cls._session
cls._session.commit()
cls._session.close()
@classmethod
def tearDownClass(cls):
reset_database()
def setUp(self):
self.session.begin_nested()
# Query for some objects and create some others, stored in a
dictionary self.test_data, using self.session
def tearDown(self):
self.session.rollback()
def test_fake(self):
thing = "thing"
def test_example(self):
self.session.begin_nested()
try:
object = Thing(hat=self.test_data["key"])
self.session.add(object)
self.session.flush()
except:
self.session.rollback()
else:
self.session.commit()
# Other tests of similar structure...
Everything runs perfectly if I remove the setUp and tearDown methods and
all tests that don't depend on self.test_data (e.g. test_fake), but if I
don't and
run all the tests then it hangs at conn.execute(DropTable(table)) in the
DropEverything
recipe. To stop the process, Ctrl-C doesn't work, I have to resort to
Ctrl-Break.
I tried running engine.dispose() before and after resetting the database,
and using
a new engine for the reset, but the problem persisted.
Any help solving this would be much appreciated.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.