marcofucci / cookiecutter-simple-django

A cookiecutter template for creating reusable Django projects quickly.
BSD 3-Clause "New" or "Revised" License
101 stars 53 forks source link

testing issue #15

Open greut opened 7 years ago

greut commented 7 years ago

The hack to put the application within the project, doesn't play well with testing. Do you have any clue to improve this situation? I have to the put the full module name in INSTALLED_APPS instead.

=============================================== test session starts ===============================================
platform linux -- Python 3.6.0, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
Django settings: chain_reaction.settings (from ini file)
rootdir: /home/yoan/work/hearc/webappII/tsuro/tsuro, inifile: tox.ini
plugins: django-3.1.2
collected 0 items / 1 errors 

===================================================== ERRORS ======================================================
_______________________________ ERROR collecting chain_reaction/apps/games/tests.py _______________________________
chain_reaction/apps/games/tests.py:3: in <module>
    from .models import Game
chain_reaction/apps/games/models.py:9: in <module>
    class Game(TimeStampedModel):
.tox/py36-pypi/lib/python3.6/site-packages/django/db/models/base.py:113: in __new__
    "INSTALLED_APPS." % (module, name)
E   RuntimeError: Model class chain_reaction.apps.games.models.Game doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
marcofucci commented 7 years ago

@greut yes, that's a known problem. To avoid that, you'd have to use absolute imports in your tests instead e.g. from games.models import Game.

I might remove the apps hack eventually as I'm not sure it adds much at this point.