"ValueError: option names {'--testrail'} already added" 使用 pytest-alure 插件启动自动测试时



正在尝试设置 pytest-testrail 插件。当我使用 --testrail --tr-config=path/to/config.cfg param 开始测试运行时,它返回错误 ValueError:选项名称 {'--testrail'} 已添加

IM 使用 Appium+pytest+Allure。它对我来说效果很好,但现在我正在尝试添加测试轨道集成。我正确设置了pytest-testrail插件(测试运行在testrail中成功创建了我的自动测试列表(,但是当我从pytest_testrail.conftest导入*添加到我自己的conftest文件时,返回错误. 我尝试多次重新安装 pytest 和 pytest-testrail 插件,但它没有帮助

最熟悉的文件:

import pytest
from appium import webdriver
from pytest_testrail.conftest import *
import sys
import os.path
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir))
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)
@pytest.fixture
def driver_setup(request):
    desired_caps = {
        //desired caps for appium driver
    }
    url = 'http://localhost:4723/wd/hub'
    request.instance.driver = webdriver.Remote(url, desired_caps)

    def teardown():
        request.instance.driver.quit()
    request.addfinalizer(teardown)

完整的错误描述:

Traceback (most recent call last):
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 415, in _importconftest
    return self._conftestpath2mod[conftestpath]
KeyError: local('/Users/anton/autotests/conftest.py')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_pytest_runner.py", line 31, in <module>
    pytest.main(args, plugins_to_load)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 55, in main
    config = _prepareconfig(args, plugins)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 200, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/hooks.py", line 289, in _call_
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 661, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 869, in parse
    self._preparse(args, addopts=addopts)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 825, in _preparse
    early_config=self, args=args, parser=self._parser
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/hooks.py", line 289, in _call_
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 724, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(early_config.known_args_namespace)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 364, in _set_initial_conftests
    self._try_load_conftest(anchor)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 370, in _try_load_conftest
    self._getconftestmodules(anchor)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 399, in _getconftestmodules
    mod = self._importconftest(conftestpath.realpath())
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 449, in _importconftest
    self.consider_conftest(mod)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 502, in consider_conftest
    self.register(conftestmodule, name=conftestmodule.__file__)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 302, in register
    ret = super().register(plugin, name)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/manager.py", line 121, in register
    hook._maybe_apply_history(hookimpl)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/hooks.py", line 336, in _maybe_apply_history
    res = self._hookexec(self, [method], kwargs)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/pytest_testrail/conftest.py", line 20, in pytest_addoption
    help='Create and update testruns with TestRail')
  File "/Users/anton/MercuryTest/mercury_env/lib/python3.6/site-packages/_pytest/config/argparsing.py", line 304, in addoption
    raise ValueError("option names %s already added" % conflict)
ValueError: option names {'--testrail'} already added

这是我与所有装饰器的测试用例示例:

import pytest
import allure
from pytest_testrail.plugin import pytestrail
@pytest.mark.usefixtures('driver_setup')
@allure.epic('application name ')
class Test_app_name:
    @allure.feature('feature')
    @pytestrail.case('C850')
    @allure.title('test title')
    @allure.severity(allure.severity_level.CRITICAL)
    def test_case_name(self):
        page = pageObjectClassWithLocatorsAndActions(self.driver)
        with allure.step('step'):
            page.do_something()

它可能与此处描述的问题重复 Pytest 测试轨道模块 - 测试运行的后测试结果

如果是这样,你不需要在你自己的conftest中导入"pytest_testrail.conftest"。

您需要在"page.do_something(("中断言某些内容才能测试插件知道"test_case_name"的状态

相关内容

  • 没有找到相关文章

最新更新