子目录中的测试
Tests in subdirectory
在 Django 1.8 中,我有一个具有此设置的应用程序:
app
|- tests/
| |- test_ook.py
| |- __init__.py
|- models.py
|- __init__.py
...
当我 运行 python manage.py test -v 2 app
时,我得到这个错误:
ImportError: 'tests' module incorrectly imported from '/home/.../site/app/tests'. Expected '/home/.../site/app'. Is this module globally installed?
这是为什么?
我该如何解决?
如果您在 app
中存在 tests.py
或 tests.pyc
文件,即与 tests
模块处于同一级别,则通常会出现此错误。
删除这些文件,它应该可以正常工作。
在 Django 1.8 中,我有一个具有此设置的应用程序:
app
|- tests/
| |- test_ook.py
| |- __init__.py
|- models.py
|- __init__.py
...
当我 运行 python manage.py test -v 2 app
时,我得到这个错误:
ImportError: 'tests' module incorrectly imported from '/home/.../site/app/tests'. Expected '/home/.../site/app'. Is this module globally installed?
这是为什么?
我该如何解决?
如果您在 app
中存在 tests.py
或 tests.pyc
文件,即与 tests
模块处于同一级别,则通常会出现此错误。
删除这些文件,它应该可以正常工作。