I have tests that require arguments, in my case these are credentials to some service:
example_test.py:
@pytest.fixture()
def artuser(pytestconfig):
return pytestconfig.getoption("artuser")
@pytest.fixture()
def artpass(pytestconfig):
return pytestconfig.getoption("artpass")
def test_nuget_get_nuget(artuser, artpass):
assert artuser == "someuser"
assert artpass == "somepassword"
conftest.py:
import pytest
def pytest_addoption(parser):
parser.addoption("--artuser", action="store")
parser.addoption("--artpass", action="store")
It works if I run:
pytest --artuser someuser --artpass somepassword
.
However, it fails if run:
python setup.py test --artuser someuser --artpass somepassword
with an an error error: option --artuser not recognized
I then tried to integrate some code from this question, just to see if the argument gets passed along, so I have something like this in my setup.py:
from setuptools import setup, find_packages
from os import path
import argparse
import sys
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('--artuser', help='required artuser argument', required=True)
args, unknown = argparser.parse_known_args()
sys.argv = [sys.argv[0]] + unknown
print(args)
setup(
name='myapp',
...
But when I run the tests, I get E AssertionError: assert None == 'someuser'
meaning the argument wasn't passed along.