pytest+allure报告最适合的版

发布时间:2019-06-11 21:21:06编辑:auto阅读(2483)

    一、环境:

    1、python3

    2、pytest (一定别选最新的,4.0.2亲测可用,否则会跳到坑二;还有项目名千万别以pytest开头)

    3、allure(github下载:https://github.com/allure-framework/allure2/releases/tag/2.10.0

    注意:下载解压完之后,记得切到bin目录下,拷贝地址;添加到环境变量path下(重启电脑生效---检验成功cmd下输入allure,如下截图环境OK)

     

    4、pytest-allure-adaptor(pip pytest-allure-adaptor)

    二、准备代码

    import pytest

    # 不带参数是默认scope='function'


    @pytest.fixture()
    def login():
    print('输入账号和密码')


    def test_01(login):
    print('test1----')


    def test_02():
    print('test2----不登录')


    def test_03(login):
    print('test3----')


    if __name__ == '__main__':
    pytest.main(['-s', 'test_001.py'])

     三、运行(cmd)

    1、切到代码所在目录下:(dir看得见就可以)

    py.test --alluredir=reports(成功执行后,会在case所在目录下生成reports文件,里面有文件OK)

     

     2.生成html

    allure generate reports(会在case所在目录生成文件夹,进入打开index.html--记得用火狐哦,谷歌是loading和404,哈哈哈哈)

     

    添加用例后,更新allure-reports:

    allure generate reports --clean

    备注:报告的生成路径,也可以自定义

      一个报告弄了2次,再次感谢前辈的踩坑记录,我才能填坑成功;记录下,万一换个电脑呢---

    参考博客:

    https://www.cnblogs.com/lza945/p/10323595.html

    https://blog.csdn.net/sinat_40831240/article/details/89711263(坑一)

    https://www.cnblogs.com/lansan0701/p/10345142.html(坑二)

关键字