python - 使用 Pytest/Python 在 Azure DevOps 中创建工作项时出错
问题描述
我正在尝试使用 Python 和requests
库创建一个工作项。
def test_create_work_item(work_items):
payload = {
'op': 'add',
'path': '/fields/System.Title',
'value': 'Sample bug'
}
pl = json.dumps(payload)
work_item = work_items.create(body=pl, type='bug')
assert work_item.status_code == 200
我收到以下错误:
{"$id":"1","innerException":null,"message":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException,Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}
Postman 可以使用相同的主体。所以不确定这里还需要什么才能让它工作。
解决方案
我对 Python 不熟悉....查看此示例:创建工作项
API 使用一组新字段:
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample task"
}
]
在您的情况下,您在请求中只使用一个字段:
{
'op': 'add',
'path': '/fields/System.Title',
'value': 'Sample bug'
}
推荐阅读
- java - 迭代一个集合,然后只执行一次流连接集合的所有元素
- c++ - 为什么这个输出“geeksforgeeks”?
- c - 在 AVR 工作室中将温度转换为电压
- jquery - jQuery datepicker 在点击时不起作用
- android - 无法实现拖放
- mysql - 使用 where 类中的同一表更新表
- validation - 如何在 Ag-Grid 中实现验证?
- java - 使用 java servlet 上传文件导致找不到资源
- bash - 期望脚本在后台运行远程脚本
- java - Team Foundation Server 与 TFS 数据库(SQL Server)的连接过多