Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Allure ModuleNotFoundError,但仅适用于包的某些函数_Python_Selenium_Testing_Report_Allure - Fatal编程技术网

Python Allure ModuleNotFoundError,但仅适用于包的某些函数

Python Allure ModuleNotFoundError,但仅适用于包的某些函数,python,selenium,testing,report,allure,Python,Selenium,Testing,Report,Allure,我开始与Allure合作,为我的测试自动化团队制作报告。我的目标是附加屏幕截图,但我遇到了一个错误。提示此错误的代码行包括: import allure #This line runs fine from allure.constants import AttachmentType #This one throws the error 它抛出:ModuleNotFoundError:没有名为'allure.constants'的模块;'“诱惑”不是一个包 我在代码的各个部分都使用了allure

我开始与Allure合作,为我的测试自动化团队制作报告。我的目标是附加屏幕截图,但我遇到了一个错误。提示此错误的代码行包括:

import allure #This line runs fine
from allure.constants import AttachmentType #This one throws the error
它抛出:
ModuleNotFoundError:没有名为'allure.constants'的模块;'“诱惑”不是一个包

我在代码的各个部分都使用了allure,没有出现错误,例如,我使用了decorator:

@allure.step("Description of a step")
因此,模块正在正确加载。在互联网上进一步检查后,我发现了一些链接,说明我应该卸载以前的软件包,如中所示的pytest allure Adapter。我这样做了,但错误保持不变

为了提供更多上下文,我使用以下softaware:

IDE:visualstudio代码 操作系统:Windows7 Python版本:3.6 诱惑测试:2.8.12
allure python commons:2.8.12

在allure的版本中,我使用的allure.constants似乎不存在

我解决了我的问题,将该行更改为:

from allure import attachment_type
然后,拍摄屏幕截图并将其添加到报告中:

allure.attach('screenshot', driver.get_screenshot_as_png(), type=attachment_type.PNG)
我希望这对将来的其他人有所帮助