Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/1380.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Honor environment markers in ``requires`` list - by :user:`asottile`
3 changes: 3 additions & 0 deletions src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,9 @@ def ensure_requires_satisfied(config, requires, min_version):
# noinspection PyBroadException
try:
package = requirements.Requirement(require)
# check if the package even applies
if package.marker and not package.marker.evaluate({"extra": ""}):
continue
package_name = canonicalize_name(package.name)
if package_name not in exists:
deps.append(DepConfig(require, None))
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_provision_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def test_provision_missing(initproj, cmd):
minversion = 3.7.0
requires =
setuptools == 40.6.3
pyparsing!=2.4.1,!=2.4.1.1;python_version=="3.4"
# remove when 2.4.2 is released or python3.4 is dropped
pyparsing!=2.4.1,!=2.4.1.1
[testenv]
commands=python -c "import sys; print(sys.executable); raise SystemExit(1)"
"""
Expand Down
37 changes: 26 additions & 11 deletions tests/unit/session/test_provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def test_provision_min_version_is_requires(newconfig, next_tox_major):
with pytest.raises(MissingRequirement) as context:
newconfig(
[],
"""
"""\
[tox]
minversion = {}
""".format(
""".format(
next_tox_major
),
)
Expand All @@ -45,10 +45,10 @@ def test_provision_min_version_is_requires(newconfig, next_tox_major):
def test_provision_tox_change_name(newconfig):
config = newconfig(
[],
"""
"""\
[tox]
provision_tox_env = magic
""",
""",
)
assert config.provision_tox_env == "magic"

Expand All @@ -58,12 +58,12 @@ def test_provision_basepython_global_only(newconfig, next_tox_major):
with pytest.raises(MissingRequirement) as context:
newconfig(
[],
"""
"""\
[tox]
minversion = {}
[testenv]
basepython = what
""".format(
""".format(
next_tox_major
),
)
Expand All @@ -77,12 +77,12 @@ def test_provision_basepython_local(newconfig, next_tox_major):
with pytest.raises(MissingRequirement) as context:
newconfig(
[],
"""
"""\
[tox]
minversion = {}
[testenv:.tox]
basepython = what
""".format(
""".format(
next_tox_major
),
)
Expand All @@ -95,10 +95,10 @@ def test_provision_bad_requires(newconfig, capsys, monkeypatch):
with pytest.raises(BadRequirement):
newconfig(
[],
"""
"""\
[tox]
requires = sad >sds d ok
""",
""",
)
out, err = capsys.readouterr()
assert "ERROR: failed to parse InvalidRequirement" in out
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_provision_non_canonical_dep(
initproj(
"w-0.1",
{
"tox.ini": """
"tox.ini": """\
[tox]
envlist = py
requires =
Expand All @@ -231,6 +231,21 @@ def test_provision_non_canonical_dep(
result.assert_success(is_run_test_env=False)


def test_provision_requirement_with_environment_marker(cmd, initproj):
initproj(
"proj",
{
"tox.ini": """\
[tox]
requires =
package-that-does-not-exist;python_version=="1.0"
"""
},
)
result = cmd("-e", "py", "-vv")
result.assert_success(is_run_test_env=False)


def space_path2url(path):
at_path = str(path)
if " " not in at_path:
Expand Down