如何修复“ValueError:选项名称{'-alluredir'}已添加”?

问题描述 投票:0回答:1

我使用 SeleniumWebdriver 编写了代码并对其进行了测试。为了构建测试结果报告,我添加了 allure-pytest 模块。当尝试运行测试时,我收到错误:

ValueError: option names {'--alluredir'} already added

我有另一个类似的项目,使用模块 allure-pytest,但它位于不同的目录中,并且未链接到当前目录 尝试通过重新安装模块 allure-pytest 来修复错误,但没有成功。请帮我解决这个问题

代码示例:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Authorize:
    path = "/Web/Login"

    def __init__(self, driver):
        self.driver = driver

    def login_page_open_check(self, browse):
        self.driver.get(browse.url + self.path)
        browse = self.driver
        browse.wait = WebDriverWait(browse, 3, 1)
        browse.wait.until(EC.url_to_be('http://10.10.104.61/sio.test/156/ESOG.Main.Web/Web/Login'))
        browse.wait.until(EC.presence_of_element_located((By.CLASS_NAME, "wrap-login")))
        browse.wait.until(EC.presence_of_element_located((By.CLASS_NAME, "auth-form-title")))
        browse.wait.until(EC.presence_of_element_located((By.ID, "Username")))
        browse.wait.until(EC.presence_of_element_located((By.ID, "Password")))
        browse.wait.until(EC.presence_of_element_located((By.XPATH,
                                                          "//*[@class='es-btn primary btn-auth w-100 ' and text()='Enter']")))
        browse.wait.until(EC.presence_of_element_located((By.CLASS_NAME, "txt-auth")))

pytest.ini 示例

[pytest]
addopts = --alluredir allure-results

测试示例

import allure
from cio_pageobject.cio_authorization import *


@allure.severity(allure.severity_level.BLOCKER)
@allure.title("Open start page")
def test_login_page_check(browse):
    user = Authorize(browse)
    with allure.step("Open start page"):
        try:
            user.login_page_open_check(browse)
        except AssertionError:
            allure.attach(browse.get_screenshot_as_png(), name='Error',
                          attachment_type=allure.attachment_type.PNG)
        raise AssertionError("Error")

错误示例:

  File "C:\Users\nkochetkov\.virtualenvs\pythonProject-VWl9IHiG\lib\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\nkochetkov\.virtualenvs\pythonProject-VWl9IHiG\lib\site-packages\allure_pytest\plugin.py", line 25, in pytest_addoption
    help="Generate Allure report in the specified directory (may not exist)")
  File "C:\Users\nkochetkov\.virtualenvs\pythonProject-VWl9IHiG\lib\site-packages\_pytest\config\argparsing.py", line 355, in addoption
    raise ValueError("option names %s already added" % conflict)
ValueError: option names {'--alluredir'} already added
python pytest allure
1个回答
0
投票

就我而言,我遇到了这个问题,因为我安装了

allure-pytest
pytest-allure-adopter
,并且引发了冲突。为了规避这个问题,我卸载了
pytest-allure-adopter
并仅保留 allure-pytest。

pip uninstall pytest-allure-adopter 

然后你可以再次尝试执行

pytest --alluredir="./reports"
© www.soinside.com 2019 - 2024. All rights reserved.