Skip to content

Commit 9ee972e

Browse files
daneahgaborbernat
authored andcommitted
Fix global configuration fallback in Jenkins runs (#1466)
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>
1 parent f324edf commit 9ee972e

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Chris Jerdonek
1919
Chris Rose
2020
Clark Boylan
2121
Cyril Roelandt
22+
Dane Hillard
2223
David Staheli
2324
Ederag
2425
Eli Collins

docs/changelog/1428.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix fallback to global configuration when running in Jenkins. - by :user:`daneah`

src/tox/_pytestplugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ def check_os_environ_stable():
102102

103103
@pytest.fixture(name="newconfig")
104104
def create_new_config_file(tmpdir):
105-
def create_new_config_file_(args, source=None, plugins=()):
105+
def create_new_config_file_(args, source=None, plugins=(), filename="tox.ini"):
106106
if source is None:
107107
source = args
108108
args = []
109109
s = textwrap.dedent(source)
110-
p = tmpdir.join("tox.ini")
110+
p = tmpdir.join(filename)
111111
p.write(s)
112112
tox.session.setup_reporter(args)
113113
with tmpdir.as_cwd():

src/tox/config/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,12 @@ def line_of_default_to_zero(section, name=None):
991991
self.config = config
992992

993993
prefix = "tox" if ini_path.basename == "setup.cfg" else None
994+
fallbacksection = "tox:tox" if ini_path.basename == "setup.cfg" else "tox"
994995

995996
context_name = getcontextname()
996997
if context_name == "jenkins":
997998
reader = SectionReader(
998-
"tox:jenkins", self._cfg, prefix=prefix, fallbacksections=["tox"]
999+
"tox:jenkins", self._cfg, prefix=prefix, fallbacksections=[fallbacksection]
9991000
)
10001001
dist_share_default = "{toxworkdir}/distshare"
10011002
elif not context_name:

tests/unit/config/test_config.py

+11
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,17 @@ def test_quiet(self, args, expected, newconfig):
21042104
config = newconfig(args, "")
21052105
assert config.option.quiet_level == expected
21062106

2107+
def test_substitution_jenkins_global(self, monkeypatch, newconfig):
2108+
monkeypatch.setenv("HUDSON_URL", "xyz")
2109+
config = newconfig(
2110+
"""
2111+
[tox:tox]
2112+
envlist = py37
2113+
""",
2114+
filename="setup.cfg",
2115+
)
2116+
assert "py37" in config.envconfigs
2117+
21072118
def test_substitution_jenkins_default(self, monkeypatch, newconfig):
21082119
monkeypatch.setenv("HUDSON_URL", "xyz")
21092120
config = newconfig(

0 commit comments

Comments
 (0)