allure-pytest:AttributeError:'模块'对象没有属性'attachment_type'

时间:2018-12-21 02:36:51

标签: python selenium pytest allure

我正在使用pytest和allure-pytest来自动化我的Web应用程序测试用例。 我的测试用例具有以下格式:

import allure
from selenium import webdriver
class Test_Abc():

    options = webdriver.ChromeOptions()
    options.add_argument("--no-sandbox")
    options.add_argument("--foreground")
    options.add_argument('disable-infobars')
    options.add_argument("--disable-extensions")
    driver = webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=options.to_capabilities())

    def test_check_reapply_page_001(self):
        allure.attach(self.driver.get_screenshot_as_png(), "Failed", allure.attachment_type.PNG)

运行测试用例时,在allure.attach命令处返回错误:

AttributeError:“模块”对象没有属性“ attachment_type”

请告诉我如何克服此错误?

库:

allure-pytest == 2.5.4

allure-python-commons == 2.5.4

pytest == 3.7.0

硒== 3.141.0

1 个答案:

答案 0 :(得分:1)

尝试使用type allure module attachment type constant,它是定义了Enum属性的extension

为了吸引:

from allure.constants import AttachmentType

allure.attach('screenshot', driver.get_screenshot_as_png(), type=AttachmentType.PNG)

对于魅力2:

from allure_commons.types import AttachmentType

allure.attach(driver.get_screenshot_as_png(), name="Screenshot", attachment_type=AttachmentType.PNG)

编辑:

看看allures own attachment tests。例如:

 allure.attach(xml_body, attachment_type=allure.attachment_type.XML)