pytest - unrecognized argument on cli invocation, despite being defined

Viewed 1911

This works on Windows without problems, but crashes on Linux.

python setup.py test --addopts '--config myconf.ini'

I have defined a custom argument for testing to provide a test user credentials via a config file:

tests/conftest.py:

def pytest_addoption(parser):
    parser.addoption('--config', default='conf.ini', help='Path to the testing config file.')


@pytest.fixture(scope='session')
def configfile(request):
    return request.config.getoption("--config")

This is how I use it in testing files:

def test_foo(configfile):
    print(configfile)

On Windows, this works fine. On Linux, however, I get this (setup.cfg is configured to invoke pytest, so this is pytest's err output)

usage: setup.py [options] [file_or_dir] [file_or_dir] [...]
setup.py: error: unrecognized arguments: --config
  inifile: None
  rootdir: /uupmaker

What is interesting though, if I pass a filename to --config fn that does not exist, no error is thrown and the tests run normally (albeit as if there was no config file defined).

Have I overlooked something? Why won't this work?


Edit: pip freeze --all output:

certifi==2017.7.27.1
chardet==3.0.4
colorama==0.3.9
coverage==4.4.1
defusedxml==0.5.0
idna==2.6
jenkinsapi==0.3.4
jira==1.0.10
lxml==3.8.0
oauthlib==2.0.3
pbr==3.1.1
pip==9.0.1
py==1.4.34
pytest==3.2.2
pytest-runner==2.12.1
python-dateutil==2.6.1
pytz==2017.2
reaver==0.1.5
requests==2.18.4
requests-oauthlib==0.8.0
requests-toolbelt==0.8.0
setuptools==28.8.0
six==1.10.0
teamcity-messages==1.21
urllib3==1.22

Using Python 3.6.1

setup.cfg:

[aliases]
test=pytest

This is the minimal working example for me: https://github.com/melkamar/pytest-setuppy-err

Simply clone that folder and run python3 setup.py test --addopts "-s --config foo.bar" and it should fail on Linux.

0 Answers
Related