【发布时间】:2017-02-16 16:25:51
【问题描述】:
我正在使用 pycharm 并尝试运行单个测试。我的“运行所有测试有效(使用 py.test),但我想运行特定测试。当我尝试运行 Nosetest 时,我收到此错误:
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
我的 wsgi.py 看起来像这样:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "v3.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
【问题讨论】:
-
您是否尝试过使用 py.test 运行特定测试?
py.test [module_filepath]::[name_of_test](来源:doc.pytest.org/en/latest/usage.html) -
你的意思是在终端?像 python manage.py py.test [[module_filepath] : : [name_of_test]
-
您的 wsgi 文件与运行测试无关。但是你至少需要展示你是如何配置你的测试的,以及你用来运行它们的命令。
-
@Marviel 您的示例适用于特定模块甚至测试类。 python -m pytest test_services.py::TestUpgradeToInvoice 但是也可以只测试函数吗?
-
@Marviel 我如何通知您的答案作为答案?
标签: python django unit-testing pycharm nose