1

Trying to setup pytest-testrail plugin. When I start test run using --testrail --tr-config=path/to/config.cfg param, it returns error ValueError: option names {'--testrail'} already added

im using appium+pytest+allure. It works well for me, but now im trying to add testrail integration. I setup pytest-testrail plugin correct(test run successfully created in testrail with list of my auto test), but when I add from pytest_testrail.conftest import * to my own conftest file, in return error . I try to reinstall pytest and pytest-testrail plugin multiple times, but it doesn't help

conftest file:

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)

full error description:

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

here example of my test cases with all decorators:

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()
Anton A
  • 13
  • 1
  • 5
  • Why are you importing `pytest_testrail.conftest`? – hoefling Aug 06 '19 at 15:54
  • without import its work well, test run in testrail created, but all test remains untested. I think it is because part of code pytest-testrail plugin don't start (I don't see any output in console when plugin push test cases into testrail, my testran just finish and nothing happened, not single error with integration), And I think , importing pytest_testrail.conftest like in GitHub example (https://github.com/allankp/pytest-testrail/blob/master/tests/livetest/conftest.py) will help me to fix this issue – Anton A Aug 06 '19 at 16:17
  • If you can run `pytest --testrail` without the error `Unrecognized argument` being raised, you can be sure the `testrail` plugin is started properly. Your issue is not related to the plugin, rather to your tests - show an example of a test that is not found, including test function signature from code (`def test...(): ...`, including decorators) and its full path (`/Users/you/project/tests/test_module.py::TestCls::test_func[test_param]` etc). – hoefling Aug 06 '19 at 16:40
  • The Github example you are referring to is not an example; it's a workaround the plugin author uses to import code from repository to be able to run the tests locally. Don't use it. Also, don't just blindly copy some code (e.g. the `sys.path.append` line) when you don't understand what it's doing - in your case, it adds the `/Users/anton` directory to Python's module search path. It will do more harm than good. – hoefling Aug 06 '19 at 16:43
  • Thanks for you help and tips. Pytest-testrail plugin successfully create test run with all my autotest included in testrail site, so I think plugin starts correct. I add example of my test cases with all decorators in general description. In my case, pytets-testrail don't mark all cases passed/failed after testrun finish. Allure generate correct report with all corrected test case statuses – Anton A Aug 07 '19 at 09:06
  • I'm not familiar with `testrail`, but if the tests are executed and processed correctly by one plugin, but not the other, it may be an issue with the plugin; I would [open a new issue](https://github.com/allankp/pytest-testrail/issues/new/choose) and clear that with the plugin author. – hoefling Aug 07 '19 at 10:10

1 Answers1

1

It maybe duplicate with issue described here Pytest Testrail Module - Post Test Results for Test Runs

If so, you don't need to import "pytest_testrail.conftest" in your own conftest

You need assert something in "page.do_something()" to testrail plugin knows the status of "test_case_name"

thuantp J
  • 13
  • 5