def session(request, monkeypatch):
"""Prevent the session from closing"""
# Roll back at the end of every test
request.addfinalizer(_db.session.remove)
# Prevent the session from closing (make it a no-op) and
# committing (redirect to flush() instead)
# https://alextechrants.blogspot.com/2014/01/unit-testing-sqlalchemy-apps-part-2.html
# monkeypatch.setattr(_db.session, 'commit', _db.session.flush)
monkeypatch.setattr(_db.session, 'remove', lambda: None)
评论列表
文章目录