posargs fails when providing arguments with spaces in quotes

Issue #310 on hold
Ian Cordasco
created an issue

An example tox.ini

[testenv:venv]
deps =
    flake8
commands = flake8 {posargs}

And the usage

$ tox -e venv -- --format="%(code)s:%(path)s:%(row)s:%(col)s: %(text)s"
$ tox -e venv -- --format='%(code)s:%(path)s:%(row)s:%(col)s: %(text)s'

In both cases %(text)s is not passed as part of the argument to --format but instead is passed as an argument as if the user did instead

$ tox -e venv -- --format="%(code)s:%(path)s:%(row)s:%(col)s:" "%(text)s"

No amount of escaping (either of the space or the quotes) works. What does work, however, is:

$ tox -e venv -- --format="'%(code)s:%(path)s:%(row)s:%(col)s: %(text)s'"

In other words, using both types of quotes works.

I looked but didn't see this reported anywhere else and I'm frankly not certain this is something that can be fixed.

Comments (9)

  1. George

    I have similar problems as well and would like to know how to pass arguments with spaces or even able to pass in single or double quotes

    I"m trying to run tox and pass arguments down to py.test.

    [testenv:pytest]
    deps = 
        pytest
    commands = py.test {posargs}
    

    Usage:

    $ tox -e pytest -- -k "foo bar" 
    

    instead of running

    $ py.test -k "foo bar" 
    

    it runs

    $ pytest -k foo bar
    
  2. Daniel Hahler

    You can use tox -e py35 -- -k "'foo or bar'" -s, i.e. put an additional level of quotes around it.

    It will still say the following (without quotes) though, but work:

    py35 runtests: commands[0] | py.test --lsof -rfsxX -k foo or bar -s
    

    (According to @Florian Bruhin it might not get fixed, because people might be used to this workaround already?!)

  3. Ian Cordasco reporter

    @Daniel Hahler yeah the typical workflow dilemma. Anyway, I described that hack around it above and have been just avoiding it by not using tox + posargs when necessary. I think that points to it needing to be fixed because I don't care to have to do the extra work to make tox do the right thing.

    I'm leaving the issue open anyway. At the very least tox should document this as a known quantity so others don't have to spend 30 minutes experimenting/debugging to find the right way to make this work.

  4. Jack Nicholson

    I agree too. I spent well more than 30 minutes debugging this and fixing it.

    I'm now running a patched version of tox in order to use the spaces... I wish I saw this thread before doing all that work.

    See #340 for the patch.

  5. Log in to comment