python - 如何使用 python 测试资源管理器在 VS 代码中运行特定测试
问题描述
我有 settings.json
{
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.pythonPath": "${workspaceFolder}\\venv\\Scripts\\python.exe",
"python.testing.cwd": "${workspaceFolder}\\tests",
"launch": {
"configurations": [],
"compounds": []
},
"terminal.integrated.env.windows": {
"PYTHONPATH": "${workspaceFolder}"
},
"python.envFile": "${workspaceFolder}\\.env",
"pythonTestExplorer.testFramework": "pytest",
"python.terminal.executeInFileDir": true,
"python.testing.pytestPath": "${workspaceFolder}\\venv\\Scripts\\pytest.exe",
和 .env
WORKSPACE_FOLDER=C:\work\autotests\project
PYTHONPATH=${WORKSPACE_FOLDER}
我想为 pytest 设置“用于 VS 代码的 Python 测试资源管理器”。使用此设置资源管理器收集并运行所有测试没有任何问题,但是当我尝试运行单个测试时,我收到错误错误:找不到文件或目录。我认为这是因为资源管理器正在通过具有绝对路径(如“C:/work/project/tests”)的命令收集/运行所有测试,并使用“./tests/test_module::TestClass::test_name”等命令运行单个测试,但是我不确定。我应该怎么做才能解决这个问题?
编辑
小组内容:Output > Python
c:\work1\autotests\tms-autotest\venv\Scripts\pytest.exe --override-ini junit_family=xunit1 --rootdir c:\work1\autotests\tms-autotest --junit-xml=C:\Users\EG_BAR~1\AppData\Local\Temp\tmp-1984XJ6G3mxW2rt3.xml ./tests/action_log_api_test.py::TestGetActionTypes
cwd: c:\work1\autotests\tms-autotest\tests
解决方案
推荐阅读
- xamarin - 在我的 ViewModel 构造函数中创建 ICommands 有什么好处吗?
- html - 如何编辑 SVG 以删除形状周围的空白空间?
- python - 在 Python 中编辑字典
- javascript - 试图编写一个 javascript 通过电子邮件发送我的 HTML 表单
- logging - 如何在 KeyCloak-Server-Distribution 中禁用 Jboss PeriodicRotatingFileHandler
- java - Maven:多模块项目依赖未解决(父pom)
- html - Html triangle with 100% width
- r - 在另一列中查找具有多个不同值的列中的值
- c# - 如何使我的 C# dll 程序集在 Visual Studio 对象浏览器中包含注释文本?
- java - Xero Java 库,创建发票给出“请求 URL 无效”