我不知道如何向pytest-allure添加插件。我希望你能给我一个例子。我希望在案件失败时挂钩案件的失败结果,并将其记录在诱惑报告中。 我的代码如下:conftest.py
# -*- coding: utf-8 -*-
import pytest
from allure.constants import AttachmentType
from selenium import webdriver
drvier = webdriver.Chrome()
@pytest.mark.hookwrapper(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
if rep.when == 'call':
if rep.failed:
png = item.name + '.png'
pytest.allure.attach(png, drvier.get_screenshot_as_png(), type=AttachmentType.PNG)
以下是Main()
# coding=utf-8
import subprocess
import pytest
from conf import config_path
def action(case):
pytest.main(['-s', '-q', config_path.testcase_path + case+'.py', '--alluredir', config_path.report_path])
command_report = config_path.allurecmd_path +'allure generate ' + config_path.report_path + ' -o ' + config_path.report_path
print(command_report)
progress = subprocess.Popen(command_report, shell=True)
progress.wait()
if __name__ == '__main__':
action('Login_test')
希望您能帮助我解决此问题。谢谢!