SmileyChris / django-countries

A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.
https://pypi.python.org/pypi/django-countries
MIT License
1.43k stars 290 forks source link

pytest - django1.7 #72

Closed areski closed 9 years ago

areski commented 9 years ago

I'm having some issue with pytest:

py.test appointment/tests.py       
============================================================================================================= test session starts =============================================================================================================
platform linux2 -- Python 2.7.5 -- py-1.4.24 -- pytest-2.6.2
plugins: django, pythonpath
collected 0 items / 1 errors 

=================================================================================================================== ERRORS ====================================================================================================================
____________________________________________________________________________________________________ ERROR collecting appointment/tests.py ____________________________________________________________________________________________________
appointment/tests.py:22: in <module>
    from appointment.views import calendar_setting_list, calendar_user_list, calendar_list,\
appointment/views.py:26: in <module>
    from appointment.forms import CalendarUserChangeDetailExtendForm, \
appointment/forms.py:67: in <module>
    class CalendarUserChangeDetailExtendForm(ModelForm):
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/forms/models.py:284: in __new__
    opts.help_texts, opts.error_messages)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/forms/models.py:210: in fields_for_model
    formfield = f.formfield(**kwargs)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:1064: in formfield
    return super(CharField, self).formfield(**defaults)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:823: in formfield
    defaults['choices'] = self.get_choices(include_blank=include_blank)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py:733: in get_choices
    choices = list(self.choices) if self.choices else []
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django_countries/__init__.py:61: in __iter__
    (code, force_text(name)) for code, name in self.countries.items()]
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/utils/encoding.py:85: in force_text
    s = six.text_type(s)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/utils/functional.py:144: in __text_cast
    return func(*self.__args, **self.__kw)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/utils/translation/__init__.py:83: in ugettext
    return _trans.ugettext(message)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py:325: in ugettext
    return do_translate(message, 'ugettext')
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py:306: in do_translate
    _default = translation(settings.LANGUAGE_CODE)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py:209: in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
/home/areski/.virtualenvs/newfies/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py:189: in _fetch
    "The translation infrastructure cannot be initialized before the "
E   AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
=========================================================================================================== 1 error in 0.37 seconds =================================================================

I only can get the problem sorted by removing force_text here: https://github.com/SmileyChris/django-countries/blob/master/django_countries/__init__.py#L61

I wonder if you have some advices on this?

SmileyChris commented 9 years ago

Assuming 1.7, you need to initialize Django correctly: https://docs.djangoproject.com/en/dev/releases/1.7/#standalone-scripts