summaryrefslogtreecommitdiff
path: root/tests/tox_env/python/test_python_api.py
diff options
context:
space:
mode:
authorBernát Gábor <bgabor8@bloomberg.net>2021-01-05 09:41:26 +0000
committerBernát Gábor <bgabor8@bloomberg.net>2021-01-07 09:24:24 +0000
commit965af75cc48eac5494bdf1d4aac6df43834c853a (patch)
treef8bd045da2db36b242635a0b078109147edd11e2 /tests/tox_env/python/test_python_api.py
parentf91a685d1bfc057634c5fd62c225a976706e552f (diff)
downloadtox-git-965af75cc48eac5494bdf1d4aac6df43834c853a.tar.gz
Requirement files support within deps
To support -r/-c/etc within deps we consider the deps section itself a requirements file. We forward this as such to the installer. We validate and traverse the entries within the requirements file, build the keys so we know when we need to rebuild the tox environment. If only add operation has been observed do not recreate the environment, bur rather just update it with a new requirement file install. Also added a mechanism into tox.pytest that allows enabling a short circuit into the execute API. This is useful for example to auto pass all install steps with success and a noop. All install steps now have a run id starting with install. Run ids have been altered to use the _ over the - as separator. This is to bring it inline with how the PEP-517 backend uses the function name as run it, and as such uses the _ as separator. Fold legacy dev build requires package install into install-deps from a dedicated step. Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
Diffstat (limited to 'tests/tox_env/python/test_python_api.py')
-rw-r--r--tests/tox_env/python/test_python_api.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/tox_env/python/test_python_api.py b/tests/tox_env/python/test_python_api.py
index c7256d9f..93a4b04e 100644
--- a/tests/tox_env/python/test_python_api.py
+++ b/tests/tox_env/python/test_python_api.py
@@ -1,7 +1,9 @@
from pathlib import Path
from packaging.requirements import Requirement
+from pytest_mock import MockerFixture
+from tox.pytest import MonkeyPatch, ToxProjectCreator
from tox.tox_env.python.api import PythonDep
@@ -32,3 +34,35 @@ def test_deps_req_ne() -> None:
def test_deps_repr() -> None:
dep_1 = PythonDep(Path.cwd())
assert repr(dep_1) == f"PythonDep(value={Path.cwd()!r})"
+
+
+def test_requirements_txt(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch, mocker: MockerFixture) -> None:
+ prj = tox_project(
+ {
+ "tox.ini": "[testenv]\npackage=skip\ndeps=-rrequirements.txt",
+ "requirements.txt": "nose",
+ }
+ )
+ execute_calls = prj.patch_execute(lambda r: 0 if "install" in r.run_id else None)
+ result = prj.run("r", "-e", "py")
+ result.assert_success()
+ tox_env = result.state.tox_env("py")
+
+ assert execute_calls.call_count == 1
+ exp = [
+ str(tox_env.conf["env_python"]),
+ "-I",
+ "-m",
+ "pip",
+ "--disable-pip-version-check",
+ "install",
+ "-r",
+ ]
+ got_cmd = execute_calls.call_args[0][2].cmd
+
+ assert got_cmd[:-1] == exp
+
+ req = Path(got_cmd[-1])
+ assert req.parent == tox_env.core["tox_root"]
+ assert req.name.startswith("requirements-")
+ assert req.name.endswith(".txt")