[Fixed]-How to test django application placed in subfolder?

20๐Ÿ‘

โœ…

You need both these files under your app folder:

__init__.py
models.py

They can be empty.

๐Ÿ‘คDavid Dehghan

2๐Ÿ‘

What error do you get? And what do you have under your INSTALLED_APPS in settings.py?

if you have something like

INSTALLED_APPS = (
    'django.contrib.auth',
    ...
    'apps.appname1',
    'apps.appname2',
)

and __init__.py in the apps directory then it should work.

๐Ÿ‘คdomino

1๐Ÿ‘

Just a note, the settings.py file contains a tuple so the termination character should be โ€˜)โ€™ not โ€˜}โ€™

๐Ÿ‘คperalmq

1๐Ÿ‘

In django 2.2.4 , using a folder for test files i.e. \test , instead of the default test.py file. This is what worked for me.

python manage.py test .\apps-folder\app1

If you are also using a folder for test files, make sure include a __init__.py

๐Ÿ‘คAngeluz-07

0๐Ÿ‘

Make sure apps has an __init__.py. You should be able to run your tests by app name:

python2 manage.py test appname1

This works under Django 1.3, I havenโ€™t tested any other versions.

๐Ÿ‘คZach Kelling

0๐Ÿ‘

This is a bit late as an answer, but for future reference of other peeps coming across this I was running into the same problem, and found that I needed to add an empty models.py file to the app. (It didnโ€™t need any database tables, but not having a models.py meant that the test runner was not picking it up.)

๐Ÿ‘คTom Christie

Leave a comment