Error: django.core.exceptions.AppRegistryNotReady: The translation infrastructure... in python
<p><strong>What I want to do:</strong> I'm trying to run tests with unittest for functions in my views. </p>

<p><strong>Outcome</strong>: I'm getting the following error:</p>

<p><em>....env/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 189, in _fetch
    "The translation infrastructure cannot be initialized before the "
django.core.exceptions.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.</em></p>

<p><strong>Imports used:</strong> </p>

<pre><code>import unittest
from django.test import Client
from django.core.wsgi import get_wsgi_application
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
import sys
sys.path.append('../../mysite/')
from mysite.settings import *
from views import *
application = get_wsgi_application()
</code></pre>

<p>As you can see I tried this answer with no success: <a href="http://stackoverflow.com/questions/27630155/appregistrynotready-the-translation-infrastructure-cannot-be-initialized">appregistrynotready-the-translation-infrastructure-cannot-be-initialized</a> </p>

<p>I followed this one too: <a href="http://stackoverflow.com/questions/34675593/upgrading-to-django-1-7-getting-appregistrynotready-for-translation-infrastruct">upgrading-to-django-1-7-getting-appregistrynotready-for-translation-infrastruct</a></p>

<p><strong>Imports I found with ugettext &amp; ugettext_lazy:</strong></p>

<pre><code>from django.utils.translation import ungettext, ugettext_lazy as _
from django.utils.translation import ungettext, ugettext, ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _
</code></pre>

<p>I changed them to </p>

<pre><code>from django.utils.translation import ugettext_lazy as _
</code></pre>

<p>But it didn't work either</p>

<p><strong>Some code I found with ugettext</strong></p>

<pre><code>return ugettext('%(number)d %(type)s') % {'number': delta.seconds, 100  'type': count(delta.seconds)}
</code></pre>

<p>I was wondering if there could be a problem with this.</p>

<p>I found it worked if I removed this lines from authentication/models.py:</p>

<pre><code>last_pass_change = models.DateTimeField(_("last_pass_change"), default=datetime.datetime.now())
last_failed_login = models.DateTimeField(_("last_failed_login"), default=datetime.datetime.now())
</code></pre>

<p>But I don't know how to fix it</p>

<p>Initialize the WSGI application before you import from views and settings.</p>

<pre><code>application = get_wsgi_application()    
from mysite.settings import *
from views import *
</code></pre>

python django