Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to ensure that context is properly reset #5083

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Changes from 3 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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
shell: bash -el {0}
strategy:
fail-fast: false
matrix:
@@ -288,7 +288,7 @@ jobs:
runs-on: macos-11
defaults:
run:
shell: bash -l {0}
shell: bash -el {0}
strategy:
fail-fast: false
matrix:
39 changes: 39 additions & 0 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
@@ -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,39 @@ 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 VersionOrder(CONDA_VERSION) <= VersionOrder("23.10.0"):
if not add_pip_as_python_dependency and context.solver == "libmamba":
pytest.xfail(
"conda.plan.install_actions from conda<=23.10.0 ignores .condarc files."
)
from conda.base.context import context_stack
from conda.core.subdir_data import SubdirData

# SubdirData's cache doesn't distinguish on add_pip_as_python_dependency.
SubdirData.clear_cached_local_channel_data()
mbargull marked this conversation as resolved.
Show resolved Hide resolved
# ContextStack's pop/replace methods don't call self.apply.
context_stack.apply()

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)

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)