当尝试使用./manage.py test
或pytest
运行测试时,Django项目中的所有应用程序均无法通过ModuleNotFoundError: No module named 'project.appname'
进行测试。但是,在使用./manage.py test app.tests
运行时(如果测试位于专用的测试目录中),它们的执行范围会超出“未找到模块”错误。
我认为我的配置有问题,导致此错误,但我不知道该在哪里尝试解决此问题:当我查看任何测试模块时,都看不到任何使PyCharm大喊大叫的东西。在查看Settings.py
时答案 0 :(得分:2)
从__init__.py
中删除project
文件。
例如
project/
- appname
...
...
__init__.py # Remove this one.