Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: option names already added pytest

#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
like image 466
Rajashekar Govindaswamy Avatar asked Jan 01 '23 04:01

Rajashekar Govindaswamy


1 Answers

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.

like image 100
Michał Kaczanowicz Avatar answered Jan 09 '23 04:01

Michał Kaczanowicz