#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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With