From 9ee972e7be07589c2ac09d5189c44e5943f0b51c Mon Sep 17 00:00:00 2001 From: Dane Hillard Date: Thu, 28 Nov 2019 04:21:57 -0500 Subject: [PATCH] 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 --- CONTRIBUTORS | 1 + docs/changelog/1428.bugfix.rst | 1 + src/tox/_pytestplugin.py | 4 ++-- src/tox/config/__init__.py | 3 ++- tests/unit/config/test_config.py | 11 +++++++++++ 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/1428.bugfix.rst diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 24169944b..542093804 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -19,6 +19,7 @@ Chris Jerdonek Chris Rose Clark Boylan Cyril Roelandt +Dane Hillard David Staheli Ederag Eli Collins diff --git a/docs/changelog/1428.bugfix.rst b/docs/changelog/1428.bugfix.rst new file mode 100644 index 000000000..8946cb184 --- /dev/null +++ b/docs/changelog/1428.bugfix.rst @@ -0,0 +1 @@ +Fix fallback to global configuration when running in Jenkins. - by :user:`daneah` diff --git a/src/tox/_pytestplugin.py b/src/tox/_pytestplugin.py index b22f0732d..7e9d94ab3 100644 --- a/src/tox/_pytestplugin.py +++ b/src/tox/_pytestplugin.py @@ -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(): diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index fe93d25ce..d80da5fff 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -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: diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index f90aa964a..9fd5b23ca 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -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(