I would consider creating a module test_urls.py
from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'^foo/$', lambda request: None, name='foo'))
then specify the path to test_urls.py when you call reverse in your test.
reverse('foo', 'path.to.test_urls')
If you really want to create urlconf in your test, you need to make sure that it has the urlpatterns attribute. In Django 1.4, the following works.
from django.conf.urls import patterns, url from django.core.urlresolvers import reverse class MockUrlConf(object): urlpatterns = patterns('', url(r'^foo/$', lambda request: None, name='foo')) reverse('foo', MockUrlConf)
source share