lethe3000
lethe3000

Reputation: 153

django running unittest fail while one of my app named "apps", but "runserver" works

I have a django-project, its apps like this:

enter image description here

In apps/apps, there're views/models/urls as usual.

"runserver" works fine with command

./manage.py runserver --settings=mysettings 0:8000

But when I tried to run unittest with command below, ImportError met.

./manage.py test --settings=mysettings

========================================

Traceback (most recent call last):
  File "/Users/lethe/.envs/django/lib/python2.7/site-packages/nose/loader.py", line 413, in loadTestsFromName
    addr.filename, addr.module)
  File "/Users/lethe/.envs/django/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Users/lethe/.envs/django/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/Users/lethe/PycharmProjects/phone-buddy-oms/src/apps/downloads/tests/test_downloads_models.py", line 5, in <module>
    from apps.models import (AppSource, AppCategory, App, Merchant, Apk)
ImportError: cannot import name Apk

It seems that django unittest frame cannot tell apps or apps/apps, I've tried to use django-nose to run but fail with similar errors.

Is there a solution except change the name of 'apps/apps'? thank you.

Upvotes: 3

Views: 248

Answers (1)

Roman Labunsky
Roman Labunsky

Reputation: 156

Your project home shouldn't have an init.py file, unittest mistakes your project home for a module and tries to load the tests from there but fails (because it has the same name as the app in INSTALLED_APPS).

Upvotes: 4

Related Questions