简体   繁体   English

如何从pytest固定装置清除MySQL数据库

[英]How to clear the MySQL database from pytest fixture

I am creating an API using Python Flask . 我正在使用Python Flask创建API I am trying to apply TDD (Test Driven Development) for the development. 我正在尝试为开发应用TDD(测试驱动开发)。

But whenever I am using the db.drop_all() from pytest fixture and running the test from the terminal it freezes at the time of exiting from the test. 但是,每当我从pytest 固定装置中使用db.drop_all()并从终端运行测试时,它在退出测试时都会冻结。

Sharing the code via Gist - https://gist.github.com/himadriganguly/9a431fd329897c9e9e3fb6113ff5eae1 通过Gist共享代码-https: //gist.github.com/himadriganguly/9a431fd329897c9e9e3fb6113ff5eae1

Thank you all in advance 谢谢大家

You should try forcing a session commit, as you probably have incomplete transactions: 您应该尝试强制执行会话提交,因为您可能有不完整的事务:

db.session.commit()
db.clear_all()

Check out " drop_all() freezes in Flask with SQLAlchemy ", there are people there also suggesting to close all sessions, so you should try that as well. 查看“ drop_all()使用SQLAlchemy在Flask中冻结 ”,那里的人还建议关闭所有会话,因此您也应该尝试关闭它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM