mtrichardson


Testing Django with nose and --with-doctest

Entry posted on May 15, 2009.

--with-doctest is a great nose plugin that will search out and find all the doctests in your project. To do this, it imports pretty much everything. Django's admin interface doesn't like that so much, as importing urls.py will call admin.autodiscover() again, which will cause a bunch of AlreadyRegistered exceptions. My crappy fix?

Wrap admin.autodiscover() in a try/except block: try:     admin.autodiscover() except admin.sites.AlreadyRegistered:     pass

A ton of Googling eventually led me to this random commit which had that in its urls.py - so, thanks!