Skip to content

Commit

Permalink
update basepython so that it does not warn erroneously major-only f…
Browse files Browse the repository at this point in the history
…actors (#1154)

fix #1153
  • Loading branch information
demosdemon authored and gaborbernat committed Feb 5, 2019
1 parent 76ad3e6 commit 2e9f733
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Ionel Maries Cristian
Itxaka Serrano
Jake Windle
Jannis Leidel
Joachim Brandon LeBlanc
Johannes Christ
Jon Dufresne
Josh Smeaton
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1153.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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`.
3 changes: 2 additions & 1 deletion src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{}';"
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2e9f733

Please sign in to comment.