在 python 脚本中使用 testrail api
using testrail api in python script
我有 curl 命令,但不确定如何在 python 脚本中 运行。
curl -H "Content-Type: application/json" -u "username:password" -d '{ "name":"something" }' "https://xxxxxxxx"
我打算使用子流程,但 api 文档不是很有用。
还有谁知道如何从 testrail 获取 sectionId 吗?
您可能想为此使用 requests
包。 curl 命令转换为如下内容:
import json
import requests
response = requests.post('https://xxxxxxxx',
data=json.dumps({'name': 'something'}),
headers={'Content-Type': 'application/json'},
auth=('username', 'password'))
response_data = response.json()
如果你真的想使用subprocess
,你可以这样做:
import subprocess
curl_args = ['curl', '-H', 'Content-Type: application/json', '-u', 'username:password',
'-d', '{ "name":"something" }', 'https://xxxxxxxx']
curl_output = subprocess.check_output(curl_args)
我认为后一种方法较少"Pythonic"。
这里是 TestRail 的账单。您可以在此处找到我们 Python 绑定的 link:
http://docs.gurock.com/testrail-api2/bindings-python
关于获取部分 ID,您可以使用 get_sections 方法获取 project/suite 到 return 所有部分详细信息,包括 ID。您可以在此处找到更多相关信息:
http://docs.gurock.com/testrail-api2/reference-sections#get_sections
如果您要查找特定测试用例的部分 ID,可以从 get_case 方法中获取。
我有 curl 命令,但不确定如何在 python 脚本中 运行。
curl -H "Content-Type: application/json" -u "username:password" -d '{ "name":"something" }' "https://xxxxxxxx"
我打算使用子流程,但 api 文档不是很有用。
还有谁知道如何从 testrail 获取 sectionId 吗?
您可能想为此使用 requests
包。 curl 命令转换为如下内容:
import json
import requests
response = requests.post('https://xxxxxxxx',
data=json.dumps({'name': 'something'}),
headers={'Content-Type': 'application/json'},
auth=('username', 'password'))
response_data = response.json()
如果你真的想使用subprocess
,你可以这样做:
import subprocess
curl_args = ['curl', '-H', 'Content-Type: application/json', '-u', 'username:password',
'-d', '{ "name":"something" }', 'https://xxxxxxxx']
curl_output = subprocess.check_output(curl_args)
我认为后一种方法较少"Pythonic"。
这里是 TestRail 的账单。您可以在此处找到我们 Python 绑定的 link:
http://docs.gurock.com/testrail-api2/bindings-python
关于获取部分 ID,您可以使用 get_sections 方法获取 project/suite 到 return 所有部分详细信息,包括 ID。您可以在此处找到更多相关信息:
http://docs.gurock.com/testrail-api2/reference-sections#get_sections
如果您要查找特定测试用例的部分 ID,可以从 get_case 方法中获取。