如何在 vscode 中调试单个 Django 测试? [英] How do I debug individual Django tests in vscode?

查看:36
本文介绍了如何在 vscode 中调试单个 Django 测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个启动配置,允许我在 Django 中运行所有测试,另一个允许我运行服务器,这两个都可以正常工作.

I added a launch configuration that allows me to run all tests in Django and another that allows me to run the server, both of these work fine.

我正在寻找一种调试单个文件的方法,但是在参数中使用 ${file} 给出了 django 不喜欢的正常路径.

I am looking for a way to debug an individual file, but using ${file} in the arguments gives a normal path which django doesn't like.

我想要一种将 ${file} 更改为 python 路径的方法,以便我可以在单个文件上调试我的测试.

I want a way to change ${file} into a python path so that I can debug my tests on a single file.

python manage.py test --noinput --keepdb python.path.to.my.file

在命令行中工作.

下面的配置好像差不多:

The following configuration seems to be almost right:

      {   "name": "Test File",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "test",
                "--noinput",
                "--keepdb",
                "${file}"
            ],
            "django": true
        }

但是,当我运行此配置时,出现错误,我认为这是因为 ${file} 变成了

However, when I run this configuration I get an error, which I think is because ${file} turns into

path/to/my/file 而不是 path.to.my.file.

推荐答案

没有将文件路径转换为带点名称的文件,因此您需要在 launch.json 中对其进行硬编码.

There is no translation of file path to dotted name, so you will need to hard-code that in your launch.json.

这篇关于如何在 vscode 中调试单个 Django 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆