"pytest --doctests-modules" AlreadyRegistered error

35 views
Skip to first unread message

Dave R

unread,
Jul 31, 2020, 8:53:39 PM7/31/20
to Django users
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 =========================================

Dave R

unread,
Jul 31, 2020, 9:29:39 PM7/31/20
to Django users
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.
Reply all
Reply to author
Forward
0 new messages