Python3+requests+pytest+excel+allure 接口自动化报告,生成本地服务并自动打开时失败

Python3+requests+pytest+excel+allure 接口自动化报告,生成本地服务并自动打开时失败

2023-02-09 10:10:38.496:INFO::main: Logging initialized @289ms to org.eclipse.jetty.util.log.StdErrLog
Could not serve the report
java.io.IOException: Failed to bind to activate.navicat.com/127.0.0.1:9992
    at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:346)
    at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:231)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
    at org.eclipse.jetty.server.Server.doStart(Server.java:385)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
    at io.qameta.allure.Commands.open(Commands.java:145)
    at io.qameta.allure.CommandLine.run(CommandLine.java:165)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at io.qameta.allure.CommandLine.main(CommandLine.java:88)
Caused by: java.net.BindException: Address already in use: bind
    at java.base/sun.nio.ch.Net.bind0(Native Method)
    at java.base/sun.nio.ch.Net.bind(Net.java:552)
    at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:336)
    at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
    at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:88)
    at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:342)
    ... 10 more

Process finished with exit code 0
  1. 分析原因:main.py页面点击右键-run main.py,点击两次同时生成两个main结果

  1. 解决方法:

1)关闭第一个main文件就可以

2)避免运行一次出现一次main结果,可以点击右上角红框所示地方点击运行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python是一种广泛使用的编程语言,因其易学易用、灵活性和可扩展性而备受欢迎。requestsPython的一个库,它提供了一种简单且易于使用的方式来发送HTTP请求。pytestPython的另一个库,它提供了一种用于编写和运行测试的框架。allure是一个测试报告生成工具,可以为测试结果提供美观和易读的报告。 在接口自动化测试中,可以使用Pythonrequests库来发送HTTP请求,并使用pytest框架来编写和运行测试。可以使用Excel来存储测试数据、预期结果和实际结果。使用allure工具可以生成美观的测试报告。 以下是使用Python requestspytestallure进行接口自动化测试的一般步骤: 1. 安装Pythonrequestspytestallure 2. 创建一个Excel文件,输入测试数据、预期结果和实际结果 3. 创建一个pytest测试文件,并使用requests库发送HTTP请求,比较预期结果和实际结果 4. 在pytest测试文件中添加allure装饰器,以便生成测试报告 5. 运行pytest测试文件并生成allure测试报告 例如,以下是一个使用Python requestspytestallure进行接口自动化测试的示例代码: ```python import requests import pytest import allure import openpyxl @allure.title("测试接口") @pytest.mark.parametrize("test_input, expected", [(1, "success"), (2, "fail")]) def test_api(test_input, expected): # 从Excel文件中获取测试数据和预期结果 wb = openpyxl.load_workbook("testdata.xlsx") sheet = wb.active test_data = sheet.cell(row=test_input, column=1).value expected_result = sheet.cell(row=test_input, column=2).value # 发送HTTP请求 response = requests.get("http://example.com/api", params=test_data) actual_result = response.text # 比较预期结果和实际结果 assert actual_result == expected_result, f"预期结果:{expected_result},实际结果:{actual_result}" # 添加allure描述 allure.attach("请求参数", str(test_data)) allure.attach("预期结果", str(expected_result)) allure.attach("实际结果", str(actual_result)) ``` 在上面的代码中,使用了pytest的parametrize装饰器来传递测试数据和预期结果。使用openpyxl库从Excel文件中获取测试数据和预期结果。使用requests库发送HTTP请求并比较预期结果和实际结果。使用allure的装饰器来添加测试描述。最后,运行pytest测试文件并生成allure测试报告

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值