gpt4 book ai didi

django - 仅在 Django 中测试项目

转载 作者:行者123 更新时间:2023-12-04 15:25:36 25 4
gpt4 key购买 nike

当我尝试运行时 python manage.py test在我的 Django (1.4) 项目中,我收到错误消息:

ERROR: test_site_profile_not_available (django.contrib.auth.tests.models.ProfileTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/contrib/auth/tests/models.py", line 29, in test_site_profile_not_available
del settings.AUTH_PROFILE_MODULE
File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 215, in __delattr__
delattr(self._wrapped, name)
AttributeError: AUTH_PROFILE_MODULE

这是 documented在 Django 错误中,建议仅测试特定应用程序而不是所有应用程序。但是我的项目没有应用程序, models.py只是驻留在项目根目录中。要在 Django 中测试特定的应用程序,它看起来像 this :
$ ./manage.py test animals
Note that we used animals, not myproject.animals.

这意味着无法指定要测试的根目录。我将如何仅测试我的项目目录?

请注意,此错误是 larger discussion on unit testing discovery 的一部分.

最佳答案

我建议使用 django-discover-runner .它允许您指定要测试的完整虚线路径。

If you just run ./manage.py test, it'll discover and run all tests underneath the TEST_DISCOVER_ROOT setting (a file system path). If you run ./manage.py test full.dotted.path.to.test_module, it'll run the tests in that module (you can also pass multiple modules). If you give it a single dotted path to a package (like a Django app) like ./manage.py test myapp and that package does not itself directly contain any tests, it'll do test discovery in all submodules of that package.

关于django - 仅在 Django 中测试项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10611289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com