服务测试失败或在烧瓶应用程序层上完成后,我尝试使用'drop_all':
@pytest.fixture(scope='class')
def db_connection():
db_url = TestConfig.db_url
db = SQLAlchemyORM(db_url)
db.create_all(True)
yield db_connection
db.drop_all()
某些测试通过时,“ drop_all”工作正常,但失败时,测试冻结。
因此,该解决方案解决了我的问题: https://stackoverflow.com/a/44437760/3050042
不幸的是,我对此一团糟。
当我使用'Session.close_all()'时,SQLAlchemy警告:
The Session.close_all() method is deprecated and will be removed in a future release. Please refer to session.close_all_sessions().
当我改变建议时:
AttributeError: 'scoped_session' object has no attribute 'close_all_sessions'
是的,我使用scoped_session和纯SQLAlchemy。
如何解决这个问题?
答案 0 :(得分:1)
close_all_sessions
函数在sqlalchemy.orm.session
的顶层定义。在编写此答案时,here就是它的外观。因此,您可以按以下方式使用它。
from sqlalchemy.orm.session import close_all_sessions
close_all_sessions()