Opened 13 years ago
Closed 13 years ago
#16333 closed Uncategorized (wontfix)
RegexURLResolver can get urlpatters list defined by set_urlconf, but get_resolver returns TypeError
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.3 |
Severity: | Normal | Keywords: | urlresolvers |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Example from tests:
from django.core.urlresolvers import set_urlconf, reverse from django.conf.urls.defaults import * urlpatterns = patterns('', url(r'^router/$', router, name='router'), url(r'^router/api/$', router.api, name='api'), ) class TestRpc(TestCase): def setUp(self): set_urlconf(urlpatterns) def tearDown(self): set_urlconf(None) def test_base(self): print reverse('router')
Problem is that *patterns* returns *list*, which can't be key of cache in *memoize* function, which wraps *get_resolver*. So simple:
urlpatterns = tuple(urlpatterns)
resolves this problem for my example.
Note:
See TracTickets
for help on using tickets.
I may be missing something, but why not use the
urls
option ("https://docs.djangoproject.com/en/dev/topics/testing/#urlconf-configuration) if you want to swap that out in a test case.