On Mon, Sep 7, 2009 at 6:24 AM, Oleg Oltar <oltarase...@gmail.com> wrote:

> Hi!
>
> I am trying to run unitests for one of my application.
>
> Here is the code of the test (it doesn't do anything yet)
>
> [snip]
> When I run those tests I get an error:
>
> Installing index for goserver.Game model
> .
> ----------------------------------------------------------------------
> Ran 1 test in 3.497s
>
> OK
> Destroying test database...
>
>
Well the test itself runs fine, it's afterwards that you've got a problem.


> ----------------------------------------------------------------------
>  Unit Test Code Coverage Results
> ----------------------------------------------------------------------
>

And this afterwards is not part of Django itself.  Django doesn't (yet)
provide any test coverage report like this.  So you've installed something
additional...



> Traceback (most recent call last):
>   File "manage.py", line 11, in <module>
>     execute_manager(settings)
>   [snip]

  File
> "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/commands/test.py",
> line 33, in handle
>     failures = test_runner(test_labels, verbosity=verbosity,
> interactive=interactive)
>   File
> "/opt/local/lib/python2.5/site-packages/django_test_coverage-0.1-py2.5.egg/django-test-coverage/runner.py",
> line 58, in run_tests
>     modules.extend(_package_modules(*pkg))
>   File
> "/opt/local/lib/python2.5/site-packages/django_test_coverage-0.1-py2.5.egg/django-test-coverage/runner.py",
> line 92, in _package_modules
>     modules.append(__import__(impstr + '.' + name, {}, {}, ['']))
>   File "/Users/oleg/jin/goclub/trunk/jin/goserver/admin.py", line 11, in
> <module>
>     admin.site.register(ActiveList, ActiveListAdmin)
>

which appears to be named django_test_coverage,  which further appears to be
re-importing your admin.py file, leading to the AlreadyRegistered errors.

  File
> "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/contrib/admin/sites.py",
> line 64, in register
>     raise AlreadyRegistered('The model %s is already registered' %
> model.__name__)
> django.contrib.admin.sites.AlreadyRegistered: The model ActiveList is
> already registered
> silver:jin oleg$
>
> From the coverage module I guess....
>
> Also, when I remove this line c.get('/login/')
>
> So test looks like this
>
> class GoserverTestCase(TestCase):
>     #fixtures = ['dat.json']
>
>     def setUp(self):
>         pass
>
>     def test_active_list_works(self):
>         c = Client()
>
>         self.assertEquals(True, True)
>
> There is no error at all
>
> Could you please explain the problem?
>
>
Apparently when you remove the login call then whatever triggers the
django_test_coverage to try to re-import your admin.py file goes away.  I'm
not familiar with this package so I can't explain why that is.  Where did
this package come from?  You might want to ask the author/maintainer about
this problem.

You could structure your admin.py file to avoid raising AlreadyRegistered
exceptions, but that hasn't generally been necessary since the addition of
admin.autodiscover() (prior to the 1.0 release) so that doesn't strike me as
a great answer.

I will note that I have used this package:

http://opensource.55minutes.com/trac/browser/python/trunk/django/apps/test_coverage/README.rst

for getting test coverage reports and not run into any problem like this,
even with tests that use login.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to