Friday, July 31, 2020

Re: "pytest --doctests-modules" AlreadyRegistered error

I figured this out.  I'm using Cookiecutter-Django, which puts a __init__.py for whatever reason in the root directory and this confuses pytest.  If you delete this __init__.py, everything works fine.


On Friday, July 31, 2020 at 8:53:39 PM UTC-4 Dave R wrote:
I am using doctests via pytest with the command "pytest --doctest-modules".  Unfortunately, I keep getting the following error.  I've already attached a screenshot.  Does anyone understand what's causing and how to address it?  Thanks!


============================================== ERRORS ===============================================
__________________________________ ERROR collecting main/admin.py ___________________________________
main\admin.py:25: in <module>
    admin.site.register(PoolType, PoolTypeAdmin)
..\..\..\.virtualenvs\mysite\lib\site-packages\django\contrib\admin\sites.py:109: in register
    raise AlreadyRegistered('The model %s is already registered' % model.__name__)
E   django.contrib.admin.sites.AlreadyRegistered: The model PoolType is already registered
__________________________________ ERROR collecting main/models.py __________________________________
main\models.py:36: in <module>
    class PoolType(models.Model):
..\..\..\.virtualenvs\mysite\lib\site-packages\django\db\models\base.py:111: in __new__
    "INSTALLED_APPS." % (module, name)
E   RuntimeError: Model class mysite.main.models.PoolType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
====================================== short test summary info ======================================
ERROR main/admin.py - django.contrib.admin.sites.AlreadyRegistered: The model PoolType is already r...
ERROR main/models.py - RuntimeError: Model class mysite.main.models.PoolType doesn't declare an ...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================= 2 errors in 0.62s =========================================

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20130c53-87af-4561-8309-1f4b2bef7853n%40googlegroups.com.

No comments:

Post a Comment