【问题标题】:How to clear the MySQL database from pytest fixture如何从 pytest 夹具中清除 MySQL 数据库
【发布时间】:2018-05-19 20:26:27
【问题描述】:

我正在使用 Python Flask 创建一个 API。我正在尝试应用 TDD(测试驱动开发)进行开发。

但每当我使用 pytest fixture 中的 db.drop_all() 并从终端运行测试时,它都会冻结退出测试。

通过 Gist 分享代码 - https://gist.github.com/himadriganguly/9a431fd329897c9e9e3fb6113ff5eae1

提前谢谢大家

【问题讨论】:

    标签: python python-3.x tdd flask-sqlalchemy pytest


    【解决方案1】:

    您应该尝试强制会话提交,因为您可能有不完整的事务:

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

    查看“drop_all() freezes in Flask with SQLAlchemy”,那里也有人建议关闭所有会话,所以你也应该尝试一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2015-06-24
      • 1970-01-01
      相关资源
      最近更新 更多