Skip to content

Commit

Permalink
Fix global configuration fallback in Jenkins runs (#1466)
Browse files Browse the repository at this point in the history
Fixes #1428

When running in Jenkins and using `setup.cfg`, tox would not fall back
to the [tox:tox] configuration properly. This was due to how the
fallback section name was calculated in this specific combination of
characteristics.

on-behalf-of: @ithaka <dane.hillard@ithaka.org>
  • Loading branch information
daneah authored and gaborbernat committed Nov 28, 2019
1 parent f324edf commit 9ee972e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Chris Jerdonek
Chris Rose
Clark Boylan
Cyril Roelandt
Dane Hillard
David Staheli
Ederag
Eli Collins
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1428.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix fallback to global configuration when running in Jenkins. - by :user:`daneah`
4 changes: 2 additions & 2 deletions src/tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ def check_os_environ_stable():

@pytest.fixture(name="newconfig")
def create_new_config_file(tmpdir):
def create_new_config_file_(args, source=None, plugins=()):
def create_new_config_file_(args, source=None, plugins=(), filename="tox.ini"):
if source is None:
source = args
args = []
s = textwrap.dedent(source)
p = tmpdir.join("tox.ini")
p = tmpdir.join(filename)
p.write(s)
tox.session.setup_reporter(args)
with tmpdir.as_cwd():
Expand Down
3 changes: 2 additions & 1 deletion src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,12 @@ def line_of_default_to_zero(section, name=None):
self.config = config

prefix = "tox" if ini_path.basename == "setup.cfg" else None
fallbacksection = "tox:tox" if ini_path.basename == "setup.cfg" else "tox"

context_name = getcontextname()
if context_name == "jenkins":
reader = SectionReader(
"tox:jenkins", self._cfg, prefix=prefix, fallbacksections=["tox"]
"tox:jenkins", self._cfg, prefix=prefix, fallbacksections=[fallbacksection]
)
dist_share_default = "{toxworkdir}/distshare"
elif not context_name:
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,17 @@ def test_quiet(self, args, expected, newconfig):
config = newconfig(args, "")
assert config.option.quiet_level == expected

def test_substitution_jenkins_global(self, monkeypatch, newconfig):
monkeypatch.setenv("HUDSON_URL", "xyz")
config = newconfig(
"""
[tox:tox]
envlist = py37
""",
filename="setup.cfg",
)
assert "py37" in config.envconfigs

def test_substitution_jenkins_default(self, monkeypatch, newconfig):
monkeypatch.setenv("HUDSON_URL", "xyz")
config = newconfig(
Expand Down

0 comments on commit 9ee972e

Please sign in to comment.