I have the following import line in a Django 1.4 project running in Python 2.7.6:
from django.contrib.gis.utils import GeoIP
This line works just fine 100% of the time in production and in development, but this line fails with an ImportError in test--sometimes. Given the following dummy test:
from django.test import TestCase
from django.test.client import Client
class DummyTestCase(TestCase):
def test_GET_200_response_code(self):
c = Client()
response = c.get('/')
self.assertEqual(response.status_code, 200)
If I run only the tests in this module, it fails on the response = self.c.get('/')
line:
...
File "...", line 19, in <module>
from django.contrib.gis.utils import GeoIP
ImportError: cannot import name GeoIP
However when I run the entire test suite, including this same test, it passes without problems. And, again, the import works fine in console, and in the server in dev and production.
So... why is that happening? Why would I get an ImportError only when running this single test module and never otherwise, even if I run all the tests including this module?
Note: I'm using Django 1.4 right now. I'm aware that the import path changes and will be from django.contrib.gis.geoip import GeoIP
, but the shortcut from utils is still there in 1.4, until 1.6. Either way, switching the import path demonstrates the same behavior as described above.