You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of flask_babel 3.0.0, flask babel locale context is no longer reset between flask test_client requests. Consider the following unit test and config:
Test app has this locale_selector:
from flask import has_request_context, request
def locale_selector():
if has_request_context():
return request.accept_languages.best_match(LanguageType)
return None
and then the test (assuming some basic flask app):
This test succeeded in 2.x because get_locale() would call locale_selector on each test. In 3.0.0, the locale remains cached after the first request is made, causing the second assertion to fail.
To make the second test succeed, we can use refresh:
This is because the ctx flask_babel now uses is a custom context stored on the flask global g and not the request context (3883ee7). My tests were sharing flask global between requests so I had to add a custom before_request to clear to the tests.
As of flask_babel 3.0.0, flask babel locale context is no longer reset between flask test_client requests. Consider the following unit test and config:
Test app has this locale_selector:
and then the test (assuming some basic flask app):
This test succeeded in 2.x because get_locale() would call locale_selector on each test. In 3.0.0, the locale remains cached after the first request is made, causing the second assertion to fail.
To make the second test succeed, we can use
refresh
:However, this makes the tests more poorly reflect reality.
The text was updated successfully, but these errors were encountered: