>>> 要使allure侦听器能够在测试执行过程中收集结果,只需添加 –alluredir选项并提供路径即可存储结果。
pytest --alluredir=
如果你运行后进行了用例更改,那么下次运行可能还是会查看到之前记录,可添加 –clean-alluredir 选项清除之前记录。
pytest --alluredir= --clean-alluredir
>>> 要在测试完成后查看实际报告,你需要使用allure命令行应用程序从结果生成报告。
(1)在默认浏览器中显示生成的报告
allure serve
(2)要从现有的Allure结果生成报告,可以使用以下命令:
allure generate
默认报告将生成到allure-report文件夹,你可以使用 -o标志更改目标文件夹:
allure generate -o
(3)生成报告后,可以在默认系统浏览器中将其打开,只需运行:
allure open
你也可以找到该目录,使用浏览器打开该目录下index.html。注意:有时打开会找不到数据或者乱码,如果你使用的是pycharm,请在pycharm中右击打开。
(4)如果要删除生成的报告数据,只需运行:
allure report clean
默认情况下,报告命令将在 allure-results文件夹中查找报告,如果要从其他位置使用报告,则可以使用 -o选项。
(5)你也可以使用allure help 命令查看更多帮助。
测试报告
你可以在allure报告中看到所有默认的pytest状态:只有由于一个断言错误而未成功进行的测试将被标记为失败,其他任何异常都将导致测试的状态为坏。
示例:
test_sample.py
import pytest
被测功能
def add(x, y):
return x + y
测试类
class TestAdd:
跳过用例
def test_first(self):
pytest.skip(‘跳过’)
assert add(3, 4) == 7
异常用例
def test_second(self):
assert add(-3, 4) == 1
raise Exception(‘异常’)
成功用例
def test_three(self):
assert add(3, -4) == -1
失败用例
def test_four(self):
assert add(-3, -4) == 7
conftest.py
import pytest
@pytest.fixture(scope=‘session’, autouse=True)
def db():
print(‘start’)
yield
print(‘closed’)
运行:
E:\workspace-py\Pytest>pytest test_sample.py --alluredir=report --clean-alluredir
========================================================================== test session starts ==========================================================================
platform win32 – Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items
test_sample.py sF.F [100%]
=============================================================================== FAILURES ================================================================================
__________________________________________________________________________ TestAdd.test_second __________________________________________________________________________
self = <test_sample.TestAdd object at 0x000000000464F278>
def test_second(self):
assert add(-3, 4) == 1
raise Exception('异常')
E Exception: 异常
test_sample.py:21: Exception
___________________________________________________________________________ TestAdd.test_four ___________________________________________________________________________
self = <test_sample.TestAdd object at 0x000000000464FD30>
def test_four(self):
assert add(-3, -4) == 7
E assert -7 == 7
E + where -7 = add(-3, -4)
test_sample.py:29: AssertionError
======================================================================== short test summary info ========================================================================
FAILED test_sample.py::TestAdd::test_second - Exception: 异常
FAILED test_sample.py::TestAdd::test_four - assert -7 == 7
================================================================ 2 failed, 1 passed, 1 skipped in 0.14s =================================================================
生成报告:
E:\workspace-py\Pytest>allure generate --clean report
Report successfully generated to allure-report
查看目录:
E:\workspace-py\Pytest>tree
文件夹 PATH 列表
卷序列号为 B2C1-63D6
E:.
├─.idea
├─.pytest_cache
│ └─v
│ └─cache
├─allure-report
│ ├─data
│ │ ├─attachments
│ │ └─test-cases
│ ├─export
│ ├─history
│ ├─plugins
│ │ ├─behaviors
│ │ ├─jira
│ │ ├─junit
│ │ ├─packages
│ │ ├─screen-diff
│ │ ├─trx
│ │ ├─xctest
│ │ ├─xray
│ │ └─xunit-xml
│ └─widgets
├─report
└─__pycache__
查看报告:
Overview:总览,显示用例执行情况、严重程度分布、环境信息等。
Categories:分类,按用例执行结果分类,异常错误和失败错误。
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数软件测试工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年软件测试全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上软件测试开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注软件测试)
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注软件测试)
[外链图片转存中…(img-UidDXUst-1712982501354)]
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!