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

nolar opened this Issue Mar 22, 2016 · 2 comments


None yet
3 participants
Copy link

nolar commented Mar 22, 2016

A sample script:
import pytest

def pytest_addoption(parser):
    parser.addoption('--env', action='store', dest='env')
def test_me(request):

A sample command that fails:

$ touch pytest.ini
$ py.test --env ../111/env.xml --capture=no
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --env
  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 & 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
  • ... cmdline options are in this order: py.test --capture=no --env ../111/env.xml (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.


  • Mac OS X 10.11 (does not matter)
  • Python-2.7.10
  • pytest-2.9.1
  • no other packages needed

This comment has been minimized.

Copy link

RonnyPfannschmidt commented Mar 22, 2016

i think this is a duplicate of #1435

@davehunt davehunt referenced this issue Jun 28, 2016


Fix determining rootdir from common_ancestor #1621

0 of 6 tasks complete

This comment has been minimized.

Copy link

nicoddemus commented Aug 6, 2016

Resolved in #1621

@nicoddemus nicoddemus closed this Aug 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.