在pycharm下运行python代码报错:
ModuleNotFoundError: No module named ‘allure.constants’; ‘allure’ is not a package
解决方法:(前提:安装了allure-pytest)
将程序文件中的以下代码
from allure.constants import AttachmentType
修改为:
from allure import attachment_type
再执行程序,该问题解决。
若未安装allure,则先执行以下命令进行安装:
pip install allure-pytest
有时,仅安装pytest-allure-adaptor,或者pytest-allure-adaptor、allure-pytest两个都装了,执行程序时出现以下错误:
此时,需要卸载掉pytest-allure-adaptor,卸载命令如下:
pip uninstall pytest-allure-adaptor
若已安装且只安装了allure-pytest,仍然出现该报错,则可能是之前安装的allure-pytest版本过低,可升级版本后再次尝试。