[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.

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 ‘}’

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

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.

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.)

Leave a comment