Sam*_*m T 11 pytest python-3.x visual-studio-code pytest-cov
我试图做到这一点,以便当我在测试资源管理器中运行测试时,它会同时在项目文件夹中自动生成一个 cov.xml 文件。我尝试将参数添加到 VS Code 上的 pytest 参数字段,但它似乎没有对测试资源管理器运行测试/pytest 的方式进行任何更改。我可能会错过一些东西,或者这可能是不可能的。
ncw*_*ncw 14
首先,pytest两者pytest-cov都必须通过 pip 安装:
$ pip install pytest
$ pip install pytest-cov
Run Code Online (Sandbox Code Playgroud)
在本地存储库设置中,将以下配置添加到文件中.vscode/settings.json:
$ pip install pytest
$ pip install pytest-cov
Run Code Online (Sandbox Code Playgroud)
现在您可以使用内置测试资源管理器运行测试:测试 > 运行测试。将生成 xml 文件并位于您的工作目录中。另请参阅有关报告的 pytest-cov 文档和有关 pytest 配置的 vscode 文档。正如 vscode 文档中所述,我建议还添加下面的启动配置,.vscode/launch.json以免使用 pytest-cov 中断调试:
{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"-v",
"--cov=myproj/",
"--cov-report=xml",
"--pdb",
"tests/"
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8622 次 |
| 最近记录: |