0

I am starting to work with Allure to make reports for my test automation team. My goal is to attach screenshots but I run into an error. The lines of code that prompt this error are:

import allure #This line runs fine
from allure.constants import AttachmentType #This one throws the error

Which throws: ModuleNotFoundError: No module named 'allure.constants'; 'allure' is not a package

I am using allure throughout different parts of the code without running into errors, for example I use the decorator:

@allure.step("Description of a step")

So the module is being correctly loaded. Upon further inspection on the internet I found links stating that I should uninstall previous packages such as pytest-allure-adaptor as seen in this other SO question. I did so but the error remains unchanged.

In order to give more context, I am using the following softaware:

IDE: Visual Studio Code OS: Windows 7 Python version: 3.6 allure-pytest: 2.8.12 allure-python-commons: 2.8.12

1 Answers1

0

It seems that in the version of allure that I was using allure.constants does not exist.

I solved my problem my changing that line to:

from allure import attachment_type

And then, to take the screenshot and adding it to the report:

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

I hope this helps someone else in the future.