Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/1045.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skip ``setup.cfg`` if it has no ``tox:tox`` namespace - by :user:`hroncok`
2 changes: 1 addition & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ At the moment tox supports three configuration locations prioritized in the foll
As far as the configuration format at the moment we only support standard ConfigParser_ "ini-style" format
(there is a plan to add a pure TOML one soon).
``tox.ini`` and ``setup.cfg`` are such files. Note that ``setup.cfg`` requires the content to be under the
``tox:tox`` section. ``pyproject.toml`` on the other hand is in TOML format. However, one can inline
``tox:tox`` section and is otherwise ignored. ``pyproject.toml`` on the other hand is in TOML format. However, one can inline
the *ini-style* format under the ``tool.tox.legacy_tox_ini`` key as a multi-line string.

Below you find the specification for the *ini-style* format, but you might want to skim some
Expand Down
14 changes: 13 additions & 1 deletion src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ def parseconfig(args, plugins=()):
content = toml_content["tool"]["tox"]["legacy_tox_ini"]
except KeyError:
continue
ParseIni(config, config_file, content)
try:
ParseIni(config, config_file, content)
except SkipThisIni:
continue
pm.hook.tox_configure(config=config) # post process config object
break
else:
Expand Down Expand Up @@ -1045,13 +1048,22 @@ def make_hashseed():
return str(random.randint(1, max_seed))


class SkipThisIni(Exception):
"""Internal exception to indicate the parsed ini file should be skipped"""


class ParseIni(object):
def __init__(self, config, ini_path, ini_data): # noqa
config.toxinipath = ini_path
using("tox.ini: {} (pid {})".format(config.toxinipath, os.getpid()))
config.toxinidir = config.toxinipath.dirpath()

self._cfg = py.iniconfig.IniConfig(config.toxinipath, ini_data)

if ini_path.basename == "setup.cfg" and "tox:tox" not in self._cfg:
verbosity1("Found no [tox:tox] section in setup.cfg, skipping.")
raise SkipThisIni()

previous_line_of = self._cfg.lineof

self.expand_section_names(self._cfg)
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3023,6 +3023,21 @@ def test_config_bad_pyproject_specified(initproj, capsys):
assert "ERROR:" not in out


def test_config_setup_cfg_no_tox_section(initproj, capsys):
setup_cfg = """
[nope:nope]
envlist = py37
"""
initproj("setup_cfg_no_tox-0.1", filedefs={"setup.cfg": setup_cfg})
with pytest.raises(SystemExit):
parseconfig([])

out, err = capsys.readouterr()
msg = "ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found\n"
assert err == msg
assert "ERROR:" not in out


@pytest.mark.skipif(sys.platform == "win32", reason="no named pipes on Windows")
def test_config_bad_config_type_specified(monkeypatch, tmpdir, capsys):
monkeypatch.chdir(tmpdir)
Expand Down