Open jdimmerman opened 1 year ago
This is because the ctx flask_babel now uses is a custom context stored on the flask global g
and not the request context (https://github.com/python-babel/flask-babel/commit/3883ee78b3576a0bece3420dab812897638c2450). 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.