尝试设置 pytest-testrail 插件。当我使用 --testrail --tr-config=path/to/config.cfg 参数开始测试运行时,它返回错误 ValueError: option names {'--testrail'} already added
我正在使用 appium+pytest+allure。它对我来说效果很好,但现在我正在尝试添加 testrail 集成。我正确设置了 pytest-testrail 插件(在 testrail 中成功创建了测试运行,并带有我的自动测试列表),但是当我将 from pytest_testrail.conftest import * 添加到我自己的 conftest 文件时,返回 error 。我尝试多次重新安装 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()