Flask login_user doesn't work with pytest Flask login_user doesn't work with pytest flask flask

Flask login_user doesn't work with pytest


This worked for me (based on this comment):

def test_with_authenticated_user(app):    @app.login_manager.request_loader    def load_user_from_request(request):        return User.query.first()    # now you can call client.post or similar methods


perhaps not the most streamlined way, but: "It can be convenient to globally turn off authentication when unit testing. To enable this, if either of the application configuration variables LOGIN_DISABLED or TESTING is set to True, this decorator will be ignored." via https://pythonhosted.org/Flask-Security/api.html