Reputation: 51
#conftest.py
include pytest
def pytest_addoption(parser):
parcer.addoption("--add", action="append")
@pytest.fixture(scope='session')
def adding(request):
name_value = request.config.option.add
if name_value == "plus":
arg1 = 1
arg2 = 2
return arg1, arg2
#addition.py
@mark.first
def test_Valid_US_Phone_Number_1(adding):
val1, val2 = adding
assert val1 + val2 == 3
Running the command
$pytest -m first plusplus.py --add plus
I am getting the following error, can anybody help?
File "c:\users\g702823\appdata\local\continuum1\anaconda3\lib\site-packages\_pytest\config\argparsing.py", line 72, in addoption
self._anonymous.addoption(*opts, **attrs)
File "c:\users\g702823\appdata\local\continuum1\anaconda3\lib\site-packages\_pytest\config\argparsing.py", line 303, in addoption
raise ValueError("option names %s already added" % conflict)
ValueError: option names {'--add'} already added
Upvotes: 5
Views: 9029
Reputation: 62
In my case there was a conflict with a different testrail package, that I had previously installed with pip.
I listed the testrail pip packages on my system with:
pip freeze | grep testrail
and then uninstalled the old testrail package I had with:
pip uninstall <testrail-package-name>
This solved the issue.
Upvotes: 0
Reputation: 81
You can prevent pytest
from walking into directories it shouldn't (out
and build
in my case) by adding this to pytest.ini
:
[pytest]
norecursedirs=out build
Upvotes: 1
Reputation: 2393
I resolved a similar issue by deleting a .pytest_cache
directory in the working directory.
Upvotes: 1
Reputation: 627
I had a similar issue myself, it turned out that I had another conftest.py
file copied to a directory one level higher in hierarchy, so pytest actually "saw" (and was trying to load) both of them, and he detected option with name "--add" twice.
Upvotes: 9