pytest 运行测试类,以及生成报告并且生产html文件

import pytest
from Lib.taxBeauty.login import Login
from untils.getYamlData import get_yaml_data
import allure

@allure.feature('登录模块')
class TestTaxBeautyLogin:

    data=[get_yaml_data()['shuimeiren'],get_yaml_data()['shuimeiren'],]
    @pytest.mark.parametrize('para',data)
    @allure.story('登录')
    def test_login(self,para):
        res = Login().checkUser(para)
        assert res['state'] == 0



if __name__ == '__main__':
    import os
    pytest.main(['test_appEdition.py', '-s', '-k', 'test', '--alluredir', f'{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/report/apiReport/tep'])
   #
'-s':打印出代码中的print信息。 '-k', 'test',:-k模糊搜索。搜索包含test的方法。
'--alluredir',f'{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/report/apiReport/tep':生成allure报告的地址
os.system('allure serve ../../report/apiReport/tep')
#自动起服务,打开allure报告
或者生成html报告
# os.system('allure generate allure报告文件地址 -o 生成报告的值')
tep= f'{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/report/apiReport/tep'
html = f'{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/report/apiReport/html'
os.system(f'allure generate {tep} -o {html}')

第二种在控制台:

1.生成allure报告

2.起服务

3.生成html报告

原文地址:https://www.cnblogs.com/zhuxibo/p/13990302.html