python-babel / flask-babel

i18n and l10n support for Flask based on Babel and pytz
https://python-babel.github.io/flask-babel/
Other
432 stars 159 forks source link

KeyError: 'babel' #236

Closed InoreNeronI closed 7 months ago

InoreNeronI commented 7 months ago
 =================================== FAILURES ===================================
  ___________________________ test_development_config ____________________________

      def test_development_config():
          """Development config."""
          app = Flask(import_name='test_development_config')
  >       config(app=app, obj=StageConfig)

  tests/test_config.py:19: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  tests/test_config.py:13: in config
      register_extensions(a=app)
  src/util/main.py:152: in register_extensions
      import_file(src=file, verbose=True)
  src/conf.py:22: in import_file
      return import_string(import_name=import_name)
  .tox/py/lib/python3.11/site-packages/werkzeug/utils.py:595: in import_string
      __import__(import_name)
  src/view/support.py:8: in <module>
      from form.support import SupportForm
  src/form/support.py:10: in <module>
      class SupportForm(FlaskForm):
  src/form/support.py:12: in SupportForm
      name = StringField(label=_('Name'), validators=[Length(max=35), DataRequired()])
  .tox/py/lib/python3.11/site-packages/flask_babel/__init__.py:756: in gettext
      return get_domain().gettext(*args, **kwargs)
  .tox/py/lib/python3.11/site-packages/flask_babel/__init__.py:750: in get_domain
      ctx.babel_domain = get_babel().instance.domain_instance
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

  app = <LocalProxy unbound>

      def get_babel(app=None) -> 'BabelConfiguration':
          app = app or current_app
          if not hasattr(app, 'extensions'):
              app.extensions = {}
  >       return app.extensions['babel']
  E       KeyError: 'babel'

  .tox/py/lib/python3.11/site-packages/flask_babel/__init__.py:46: KeyError

Environment:

I am using Pythonloc with Make under Ubuntu, steps to reproduce:

TkTech commented 7 months ago

Not a bug. You're using babel before setting it up. _('Name') should be lazy.