Skip to content

Commit

Permalink
Expose tox requires via the config object (#1919)
Browse files Browse the repository at this point in the history
Fixes #1918

This also fixes broken __str__ of MissingRequirement,
which is never actually used but is helpful when debugging.
  • Loading branch information
hroncok authored Feb 16, 2021
1 parent 555f3f1 commit 9db3ecf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/1918.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The value of the :conf:`requires` configuration option is now exposed via
the :class:`tox.config.Config` object - by :user:`hroncok`
4 changes: 2 additions & 2 deletions src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,11 +1295,11 @@ def run(name, section, subs, config):
feedback("--devenv requires only a single -e", sysexit=True)

def handle_provision(self, config, reader):
requires_list = reader.getlist("requires")
config.requires = reader.getlist("requires")
config.minversion = reader.getstring("minversion", None)
config.provision_tox_env = name = reader.getstring("provision_tox_env", ".tox")
min_version = "tox >= {}".format(config.minversion or Version(tox.__version__).public)
deps = self.ensure_requires_satisfied(config, requires_list, min_version)
deps = self.ensure_requires_satisfied(config, config.requires, min_version)
if config.run_provision:
section_name = "testenv:{}".format(name)
if section_name not in self._cfg.sections:
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/session/test_provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ def test_provision_min_version_is_requires(newconfig, next_tox_major):
assert config.ignore_basepython_conflict is False


def test_provision_config_has_minversion_and_requires(newconfig, next_tox_major):
with pytest.raises(MissingRequirement) as context:
newconfig(
[],
"""\
[tox]
minversion = {}
requires =
setuptools > 2
pip > 3
""".format(
next_tox_major,
),
)
config = context.value.config

assert config.run_provision is True
assert config.minversion == next_tox_major
assert config.requires == ["setuptools > 2", "pip > 3"]


def test_provision_config_empty_minversion_and_requires(newconfig, next_tox_major):
config = newconfig([], "")

assert config.run_provision is False
assert config.minversion is None
assert config.requires == []


def test_provision_tox_change_name(newconfig):
config = newconfig(
[],
Expand Down

0 comments on commit 9db3ecf

Please sign in to comment.