Tox: Error while parsing tox.ini with {posargs: tests} after line continuation

Created on 16 Jan 2017  路  3Comments  路  Source: tox-dev/tox

Here is an example tox.ini that triggers the error (edit: extra space after "posargs:" is important):

[tox]
envlist = py27

[testenv]
deps=
    pytest

commands=
    py.test --doctest-modules \
        {posargs: tests}

Running tox results in the following error:

$ tox
Traceback (most recent call last):
  File "toxvenv/bin/tox", line 11, in <module>
    sys.exit(cmdline())
  File "toxvenv/lib/python3.5/site-packages/tox/session.py", line 38, in main
    config = prepare(args)
  File "toxvenv/lib/python3.5/site-packages/tox/session.py", line 26, in prepare
    config = parseconfig(args)
  File "toxvenv/lib/python3.5/site-packages/tox/config.py", line 239, in parseconfig
    parseini(config, inipath)
  File "toxvenv/lib/python3.5/site-packages/tox/config.py", line 760, in __init__
    self.make_envconfig(name, section, reader._subs, config)
  File "toxvenv/lib/python3.5/site-packages/tox/config.py", line 791, in make_envconfig
    res = meth(env_attr.name, env_attr.default)
  File "toxvenv/lib/python3.5/site-packages/tox/config.py", line 964, in getargvlist
    return _ArgvlistReader.getargvlist(self, s)
  File "toxvenv/lib/python3.5/site-packages/tox/config.py", line 1140, in getargvlist
    (reader.section_name, "commands"))
tox.ConfigError: ConfigError: line-continuation ends nowhere while resolving for [testenv:py27] commands

pip list output:

pip (9.0.1)
pluggy (0.4.0)
py (1.4.32)
setuptools (18.2)
tox (2.5.0)
virtualenv (15.1.0)

If line continuation is placed in a different place, for example:

commands=
    py.test \
        --doctest-modules {posargs: tests} 

everything is fine.

documentation minor easy pr-merged

All 3 comments

It looks like the culprit is SectionReader._apply_factors in config.py
This nested function appears to be looking for lines like py{27,35}: my command and interprets the {posargs: tests} as a {posargs factor with a tests} command.

        def factor_line(line):
            m = re.search(r'^([\w{}\.,-]+)\:\s+(.+)', line)
            if not m:
                return line

            expr, line = m.groups()
            if any(fs <= self.factors for fs in _split_factor_expr(expr)):
                return line

The example here, http://tox.readthedocs.io/en/latest/config.html#substitutions-for-positional-arguments-in-commands shows no space between the posargs and the substitution which works if you do {posargs:tests}.

More of an FYI as I have no idea what the maintainers design intent is.

@speedyleion thanks for the update: indeed, it only fails to parse if an extra space is present after "posargs:", without it it's possible to place line continuation at any place. So I'll be using it without space now, as in the docs :) In my defence, it works even with a space, but this makes the issue super minor.

Thanks @lopuhin for reporting this and @speedyleion for checking the code and the docs. Atm I would interpret it as a documentation bug for making it not clear enough that a space is not allowed after the colon.

Was this page helpful?
0 / 5 - 0 ratings