From 48d42cece97190a2ad8f62f164be0240539904d1 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Sun, 26 Nov 2023 13:58:37 +0100 Subject: [PATCH] Add test_add_pip_as_python_dependency_from_condarc_file Signed-off-by: Marcel Bargull --- tests/test_api_build.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test_api_build.py b/tests/test_api_build.py index ff3e431ff3..5143a7a1af 100644 --- a/tests/test_api_build.py +++ b/tests/test_api_build.py @@ -12,6 +12,7 @@ import tarfile import uuid from collections import OrderedDict +from contextlib import nullcontext from glob import glob from pathlib import Path from shutil import which @@ -28,8 +29,10 @@ import conda_build from conda_build import __version__, api, exceptions from conda_build.conda_interface import ( + CONDA_VERSION, CondaError, LinkError, + VersionOrder, cc_conda_build, context, reset_context, @@ -1899,3 +1902,37 @@ def test_activated_prefixes_in_actual_path(testing_metadata): if path in expected_paths ] assert actual_paths == expected_paths + + +@pytest.mark.parametrize("add_pip_as_python_dependency", [False, True]) +def test_add_pip_as_python_dependency_from_condarc_file( + testing_metadata, testing_workdir, add_pip_as_python_dependency, monkeypatch +): + """ + Test whether settings from .condarc files are heeded. + ref: https://github.com/conda/conda-libmamba-solver/issues/393 + """ + if ( + not add_pip_as_python_dependency + and context.solver == "libmamba" + and VersionOrder(CONDA_VERSION) <= VersionOrder("23.10.0") + ): + pytest.xfail("conda.plan.install_actions from conda<=23.10.0 ignores .condarc files.") + testing_metadata.meta["build"]["script"] = ['python -c "import pip"'] + testing_metadata.meta["requirements"]["host"] = ["python"] + del testing_metadata.meta["test"] + if add_pip_as_python_dependency: + check_build_fails = nullcontext() + else: + check_build_fails = pytest.raises(subprocess.CalledProcessError) + + # For conda<=23.10.0, ContextStack's pop/replace methods don't call self.apply. + from conda.base.context import context_stack + + context_stack.apply() + + conda_rc = Path(testing_workdir, ".condarc") + conda_rc.write_text(f"add_pip_as_python_dependency: {add_pip_as_python_dependency}") + with env_var("CONDARC", conda_rc, reset_context): + with check_build_fails: + api.build(testing_metadata)