Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py.test improperly handles command line options with spaces #1471

Closed
nolar opened this issue Mar 22, 2016 · 2 comments
Closed

Py.test improperly handles command line options with spaces #1471

nolar opened this issue Mar 22, 2016 · 2 comments

Comments

@nolar
Copy link

nolar commented Mar 22, 2016

A sample script:

#conftest.py
import pytest


@pytest.hookimpl
def pytest_addoption(parser):
    parser.addoption('--env', action='store', dest='env')
#mytest.py
def test_me(request):
    print(request.config.option.env)

A sample command that fails:

$ touch pytest.ini
$ py.test --env ../111/env.xml --capture=no mytest.py
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --env mytest.py
  inifile: None
  rootdir: /Users/svasilyev/parent

Where /Users/svasilyev/parent is a parent dir for the sample scripts dir (they are in /Users/svasilyev/parent/pytest-cmdline-sample).

The error happens only when ../111/env.xml actually exists, and it is outside of the current dir with conftest.py & pytest.ini.

The error does NOT happen when:

  • ... the target file does not exists (even if it points to outer dir), or this is not a filename (just by accident, like "no" in --capture no notation).
  • ... the file exists, but it is in the local dir or any subdir: py.test --env ./env.xml --capture=no mytest.py.
  • ... cmdline options are in this order: py.test --capture=no --env ../111/env.xml mytest.py (surprise!)
  • … the same space-notation is used for built-in options (e.g., --junit-xml ../111/junit.xml)

I guess the error is caused by py.test's cmdline pre-parsing and rootdir detection: it treats the standalone cmdline option ../111/env.xml as a reference to a test file, and this is done before --env is actually added to the parser by the plugins.

I understand that plugins cannot be properly loaded before the cmdline is pre-parsed, and thus it is impossible to add all cmdline options before cmdline parsing.

Yet, python's argparse accepts both --opt=val and --opt val notations, so this is the expected behaviour. So, probably, preparsing or rootdir detection should be done a bit more carefully.

PS:

  • Mac OS X 10.11 (does not matter)
  • Python-2.7.10
  • pytest-2.9.1
  • no other packages needed
@RonnyPfannschmidt
Copy link
Member

i think this is a duplicate of #1435

@nicoddemus
Copy link
Member

Resolved in #1621

This was referenced Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants