我正在尝试这样做,以便当我在test中运行测试时,它将同时在项目文件夹中自动生成一个cov.xml文件。我尝试将参数添加到VS代码上的pytest参数字段中,但它似乎没有对测试资源管理器运行测试/pytest的方式进行任何更改。我可能错过了什么,或者这可能是不可能的。
发布于 2022-03-18 10:37:27
首先,pytest和pytest-cov都必须通过pip安装:
$ pip install pytest
$ pip install pytest-cov在本地存储库设置中,将以下配置添加到.vscode/settings.json文件中:
{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"-v",
"--cov=myproj/",
"--cov-report=xml",
"--pdb",
"tests/"
]
}现在,您可以使用内置的测试资源管理器运行测试:测试>运行测试。xml文件将生成并位于您的工作目录中。也见关于报告的pytest-cov文档和用于pytest配置的vscode文档。正如vscode文档中所述,我还建议将下面的启动配置添加到.vscode/launch.json中,以避免使用pytest-cov中断调试:
{
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"env": {
"PYTEST_ADDOPTS": "--no-cov"
},
"justMyCode": false
}
]
}https://stackoverflow.com/questions/69443189
复制相似问题