当运行这些代码时,Django 1.6.10找不到位于我的应用程序之外的测试模块(参考:https://docs.djangoproject.com/en/1.6/topics/testing/overview/#running-tests)
./manage.py test tests/app1/
./manage.py test tests/app1/test_views我一直收到这些错误
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下面是我的项目结构:
- 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,仍然找不到哪里错了。有什么需要帮忙的吗-我错过了什么
替换为/。但是,在执行时会产生相同的错误
./manage.py test tests.app1.test_views.MyTestCase
./manage.py test tests.app1.test_views.MyTestCase.test_mymethod 我得到了ValueError。
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文档,这些模式中的任何一个现在都可以工作(使用/是一种提供目录路径的方法,以发现该目录下的测试):。
./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标志吗?提前谢谢你。
发布于 2015-03-16 20:08:38
您应该将它们引用为模块,而不是路径:
./manage.py test tests.app1
./manage.py test tests.app1.test_views阅读有关运行测试in the docs的更多信息。
https://stackoverflow.com/questions/29076369
复制相似问题