diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b53bb1bfa..f5447f88b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -33,6 +33,7 @@ Ionel Maries Cristian Itxaka Serrano Jake Windle Jannis Leidel +Joachim Brandon LeBlanc Johannes Christ Jon Dufresne Josh Smeaton diff --git a/docs/changelog/1153.bugfix.rst b/docs/changelog/1153.bugfix.rst new file mode 100644 index 000000000..bfe6c356b --- /dev/null +++ b/docs/changelog/1153.bugfix.rst @@ -0,0 +1 @@ +Using ``py2`` and ``py3`` with a specific ``basepython`` will no longer raise a warning unless the major version conflicts - by :user:`demosdemon`. diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 69f47cdb4..c50c713ba 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -571,7 +571,8 @@ def basepython_default(testenv_config, value): proposed_version = "".join( str(i) for i in python_info_for_proposed.version_info[0:2] ) - if implied_version != proposed_version: + # '27'.startswith('2') or '27'.startswith('27') + if not proposed_version.startswith(implied_version): # TODO(stephenfin): Raise an exception here in tox 4.0 warnings.warn( "conflicting basepython version (set {}, should be {}) for env '{}';" diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 20913a990..339699857 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -1910,6 +1910,46 @@ def get_executable(self, envconfig): assert env_config.basepython == "python{}.{}".format(major, minor - 1) assert not recwarn.list, "\n".join(repr(i.message) for i in recwarn.list) + def test_default_single_digit_factors(self, newconfig, monkeypatch): + from tox.interpreters import Interpreters + + def get_executable(self, envconfig): + return sys.executable + + monkeypatch.setattr(Interpreters, "get_executable", get_executable) + + major, minor = sys.version_info[0:2] + + with pytest.warns(None) as lying: + config = newconfig( + """ + [testenv:py{0}] + basepython=python{0}.{1} + commands = python --version + """.format( + major, minor - 1 + ) + ) + + env_config = config.envconfigs["py{}".format(major)] + assert env_config.basepython == "python{}.{}".format(major, minor - 1) + assert len(lying) == 0, "\n".join(repr(r.message) for r in lying) + + with pytest.warns(None) as truthful: + config = newconfig( + """ + [testenv:py{0}] + basepython=python{0}.{1} + commands = python --version + """.format( + major, minor + ) + ) + + env_config = config.envconfigs["py{}".format(major)] + assert env_config.basepython == "python{}.{}".format(major, minor) + assert len(truthful) == 0, "\n".join(repr(r.message) for r in truthful) + def test_default_factors_conflict_ignore(self, newconfig, capsys): with pytest.warns(None) as record: config = newconfig(