Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test django application placed in subfolder?

I have problem with testing django apps grouped in subfolder.

Well, let me explain situation.

Standart django project structure looks like this:

django_project/
--appname1
--appname2
--appname3
--lib
--tests
--docs
settings.py 
etc...

When project structure is standart you can run tests for appname1 just by typing command in project dir:

python2 manage.py test appname1`

We decided to put all apps in subfoloder, so our project structure looks like this:

django_project/
--apps/
----appname1
----appname2
----appname3
--lib
--tests
--docs
settings.py 
etc...

All works fine, but we can't run tests for apps. I have tried folowing commands without success:

python2 manage.py test appname1
python2 manage.py test apps/appname1
python2 manage.py test apps.appname1

Is there any way for running tests using manage.py for apps that placed in subfolder, or we should write own command for running them?

UPD:

We have following error:

 Traceback (most recent call last):
  File "manage.py", line 18, in <module>
    management.execute_manager(settings)
  File "/opt/python266/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/opt/python266/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python266/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/opt/python266/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/opt/python266/lib/python2.6/site-packages/django/core/management/commands/test.py", line 37, in handle
    failures = test_runner.run_tests(test_labels)
  File "/opt/python266/lib/python2.6/site-packages/django/test/simple.py", line 312, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/opt/python266/lib/python2.6/site-packages/django/test/simple.py", line 244, in build_suite
    app = get_app(label)
  File "/opt/python266/lib/python2.6/site-packages/django/db/models/loading.py", line 140, in get_app
    raise ImproperlyConfigured("App with label %s could not be found" % app_label)
django.core.exceptions.ImproperlyConfigured: App with label appname1 could not be found

We have installed apps setting like:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'project_name.apps.appname1',
'project_name.apps.appname2',
'project_name.apps.appname3',
 )
like image 456
Nikolay Fominyh Avatar asked Jun 26 '11 11:06

Nikolay Fominyh


2 Answers

You need both these files under your app folder:

__init__.py
models.py

They can be empty.

like image 140
David Dehghan Avatar answered Sep 20 '22 18:09

David Dehghan


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.

like image 42
domino Avatar answered Sep 21 '22 18:09

domino