小编And*_*rii的帖子

Django 应用程序的 VScode unittest 测试发现设置

我有一个带有一些单元测试的 django 应用程序。我想在 VScode v.1.59.1 中运行\调试它们。

我的 ./vscode/settings.json 看起来像这样:

{
    "python.testing.unittestArgs": [
        "-v",
        "-s",
        "./routes/tests",
        "-p",
        "test*.py"
    ],
    "python.testing.pytestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.unittestEnabled": true,
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行\发现测试时,我有以下输出:

ImportError: Failed to import test module: test_utils
...
django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Run Code Online (Sandbox Code Playgroud)

当我尝试使用命令以常规 django 方式运行测试时:

python manage.py test
Run Code Online (Sandbox Code Playgroud)

测试工作正常。

请帮助我设置 VScode 来运行 django 单元测试。

PS:我无法安装 pytest,这应该在不安装任何新模块的情况下完成。

django django-rest-framework python-unittest visual-studio-code

5
推荐指数
1
解决办法
488
查看次数