代码:
# -*-coding:utf-8-*-
__author__ = 'YL'
import allure
import pytest
@allure.feature("登录模块")
class TestLogin:
@allure.story("登录成功")
def test_login_success(self):
with allure.step("步骤1,打开应用"):
print("打开应用")
with allure.step("步骤2,启动程序"):
print("启动程序")
print("登录成功")
@allure.story("登录失败")
def test_login_fail(self):
print("登录失败")
@allure.story("登录用户名缺失")
def test_login_lose_user_name(self):
print("登录缺失用户名")
@allure.story("登录密码缺失")
def test_login_lose_password(self):
print("登录缺失密码")
执行 ‘’pytest test_allure.py --allure-features=“登录模块” -vs --alluredir=./resultAllure“结果如下:
D:\Program Files\pycharm\ck159890793\testing>pytest test_allure.py --allure-features=“登录模块” -vs --alluredir=./resultAllure
======================================================================= test session starts ========================================================================
platform win32 – Python 3.7.1, pytest-6.0.2, py-1.9.0, pluggy-0.13.1 – d:\python\python.exe
cachedir: .pytest_cache
rootdir: D:\Program Files\pycharm\ck159890793\testing, configfile: pytest.ini
plugins: allure-pytest-2.8.18
collected 4 items
test_allure.py::TestLogin::test_login_success 打开应用
启动程序
登录成功
PASSED
test_allure.py::TestLogin::test_login_fail 登录失败
PASSED
test_allure.py::TestLogin::test_login_lose_user_name 登录缺失用户名
PASSED
test_allure.py::TestLogin::test_login_lose_password 登录缺失密码
PASSED
执行完之后能正常生产结果文件夹
但是在执行 allure serve ./resultAllure 时报错
D:\Program Files\pycharm\ck159890793\testing>allure serve ./resultAllure
Generating report to temp directory...
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\3437984597559788761\allure-report
Starting web server...
2020-10-25 11:22:49.669:INFO::main: Logging initialized @11732ms to org.eclipse.jetty.util.log.StdErrLog
Could not open the report in browser, try to open it manually http://192.168.3.17:51775/: {}
java.io.IOException: Failed to open http://192.168.3.17:51775/. Error message: 找不到应用程序
at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:90)
at sun.awt.windows.WDesktopPeer.browse(WDesktopPeer.java:76)
at java.awt.Desktop.browse(Desktop.java:385)
at io.qameta.allure.Commands.openBrowser(Commands.java:221)
at io.qameta.allure.Commands.open(Commands.java:152)
at io.qameta.allure.Commands.serve(Commands.java:136)
at io.qameta.allure.CommandLine.run(CommandLine.java:159)
at java.util.Optional.orElseGet(Optional.java:267)
at io.qameta.allure.CommandLine.main(CommandLine.java:88)
执行 allure generate ./resultAllure 生成的报告可正常查看