首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Django 1.6测试发现无法找到测试模块

Django 1.6测试发现无法找到测试模块
EN

Stack Overflow用户
提问于 2015-03-16 20:04:38
回答 1查看 420关注 0票数 0

当运行这些代码时,Django 1.6.10找不到位于我的应用程序之外的测试模块(参考:https://docs.djangoproject.com/en/1.6/topics/testing/overview/#running-tests)

代码语言:javascript
复制
./manage.py test tests/app1/
./manage.py test tests/app1/test_views

我一直收到这些错误

代码语言:javascript
复制
django.core.exceptions.ImproperlyConfigured: App with label tests/app1/ could not be found

django.core.exceptions.ImproperlyConfigured: App with label tests/app1/test_views could not be found

下面是我的项目结构:

代码语言:javascript
复制
- project
    - app1
        - __init__.py
        - models.py
        - views.py
        - forms.py
        - admins.py
    - app2
        - ..as per above
    - tests
        - __init__.py (blank)
        - app1
           - __init__.py (blank)
           - test_views.py
           - test_forms.py
        - app2
           - __init__.py (blank)
           - test_views.py
           - test_walkthrough.py    

我读了几遍Django Discovery runner,仍然找不到哪里错了。有什么需要帮忙的吗-我错过了什么

替换为/。但是,在执行时会产生相同的错误

代码语言:javascript
复制
./manage.py test tests.app1.test_views.MyTestCase
./manage.py test tests.app1.test_views.MyTestCase.test_mymethod   

我得到了ValueError。

代码语言:javascript
复制
ValueError: Test label  'tests.app1.test_views.MyTestCase.test_mymethod' should be of the form app.TestCase or app.TestCase.test_method

进一步更新:在将--testrunner='django.test.runner.DiscoverRunner‘添加到命令行时,我终于让它正常工作了。根据Django文档,这些模式中的任何一个现在都可以工作(使用/是一种提供目录路径的方法,以发现该目录下的测试):。

代码语言:javascript
复制
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests.app1
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests.app1.test_views.MyTestCase
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests/app1/

仍然不知道我为什么要提供--testrunner值。我也在我的代码中使用了夹层,并再次确认settings.TEST_RUNNER指向django.test.runner.DiscoverRunner

有人能解释一下为什么我需要django 1.6中的--testrunner标志吗?提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2015-03-16 20:08:38

您应该将它们引用为模块,而不是路径:

代码语言:javascript
复制
./manage.py test tests.app1
./manage.py test tests.app1.test_views

阅读有关运行测试in the docs的更多信息。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29076369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档