Frage

My app is using django-localeurl. My unit testing were ok in django 1.5.5 but since I moved to django 1.6.2, i have many errors because of status 301 in response.

It seems that this is caused by wrong urls which don't take into account the locale prefix. In other words, when calling reverse in a unit test, the usual django reverse is called rather than the localeurl reverse.

I've checked that the patch_reverse is called in the unittest. My call is at the top of my main urls.py. It seems ok.

But for any reason, the django reverse is restored by something.

This problem seems to occur only during unit testing. The urls are correctly localized when running the app.

I think the problem correspond to the following issue in django-localeurl : https://bitbucket.org/carljm/django-localeurl/issue/22/test-problem

Does anybody know what can cause this problem (unit testing mechanism have changed in django 1.6, is it the reason?) and how to fix it?


Update

The problem doesn't occur if I force the following setting

TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'
War es hilfreich?

Lösung

It seems that the cause is that the DiscoverRunner (new way to run tests in django 1.6) imports the test modules in advance in order to build the list of tests to be run.

As a consequence, the imports of the test modules are executed before the import of settings and urls. Then, the module imports the django reverse before it get patched in urls.py

My fix is to force the patch at the beginning of my test modules. I think it is not perfect solution but it works.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top