Skip to content

Commit 9db3ecf

Browse files
authored
Expose tox requires via the config object (#1919)
Fixes #1918 This also fixes broken __str__ of MissingRequirement, which is never actually used but is helpful when debugging.
1 parent 555f3f1 commit 9db3ecf

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

docs/changelog/1918.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The value of the :conf:`requires` configuration option is now exposed via
2+
the :class:`tox.config.Config` object - by :user:`hroncok`

src/tox/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,11 +1295,11 @@ def run(name, section, subs, config):
12951295
feedback("--devenv requires only a single -e", sysexit=True)
12961296

12971297
def handle_provision(self, config, reader):
1298-
requires_list = reader.getlist("requires")
1298+
config.requires = reader.getlist("requires")
12991299
config.minversion = reader.getstring("minversion", None)
13001300
config.provision_tox_env = name = reader.getstring("provision_tox_env", ".tox")
13011301
min_version = "tox >= {}".format(config.minversion or Version(tox.__version__).public)
1302-
deps = self.ensure_requires_satisfied(config, requires_list, min_version)
1302+
deps = self.ensure_requires_satisfied(config, config.requires, min_version)
13031303
if config.run_provision:
13041304
section_name = "testenv:{}".format(name)
13051305
if section_name not in self._cfg.sections:

tests/unit/session/test_provision.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@ def test_provision_min_version_is_requires(newconfig, next_tox_major):
4747
assert config.ignore_basepython_conflict is False
4848

4949

50+
def test_provision_config_has_minversion_and_requires(newconfig, next_tox_major):
51+
with pytest.raises(MissingRequirement) as context:
52+
newconfig(
53+
[],
54+
"""\
55+
[tox]
56+
minversion = {}
57+
requires =
58+
setuptools > 2
59+
pip > 3
60+
""".format(
61+
next_tox_major,
62+
),
63+
)
64+
config = context.value.config
65+
66+
assert config.run_provision is True
67+
assert config.minversion == next_tox_major
68+
assert config.requires == ["setuptools > 2", "pip > 3"]
69+
70+
71+
def test_provision_config_empty_minversion_and_requires(newconfig, next_tox_major):
72+
config = newconfig([], "")
73+
74+
assert config.run_provision is False
75+
assert config.minversion is None
76+
assert config.requires == []
77+
78+
5079
def test_provision_tox_change_name(newconfig):
5180
config = newconfig(
5281
[],

0 commit comments

Comments
 (0)