【问题标题】:visual studio code django debug configuration doesn't recognize test filesvisual studio code django 调试配置无法识别测试文件
【发布时间】:2023-01-08 02:54:10
【问题描述】:

我有一个标准的项目设置,其中我的 test.py 在应用程序文件夹中。

像这样:

django_project/my_app/tests.py

当我手动运行

py manage.py test

它识别我的测试文件。

使用此调试配置时,它不会运行测试。

Found 0 test(s).
System check identified no issues (0 silenced).      

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

我怎样才能正确设置它们?

启动.json:

{
    "name": "Python: Django",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}\\django_project\\manage.py",
    "args": [
        "test"
    ],
    "django": true,
    "justMyCode": true
},

【问题讨论】:

  • 配置中 manage.py 的路径是正确的。 “${workspaceFolder}\\django_project\\manage.py” 我在“args”下使用“runserver”而不是“test”运行这个配置并且它有效。所以它一定是不同的东西。有任何想法吗?

标签: python django visual-studio-code django-testing


【解决方案1】:

我使用了一个简单的例子,但没有遇到任何问题。我认为这可能与您的launch.json文件中manage.py的路径有关。您可以删除 launch.json 并使用调试中的自动创建来获取新设置。

这是我的launch.json

"configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}\manage.py",
            "args": [
                "test"
            ],
            "django": true,
            "justMyCode": true
        }
    ]

我的manage.py在工作区下,如图:

当然,我还有一个建议。你可以试试pytest

【讨论】:

    【解决方案2】:

    @Pfinnn 我在 VSCode 中也有同样的情况。你找到你的请求的答案了吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-13
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多