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

Test to make sure virtual packages aren't included in lockfiles #583

Merged
merged 1 commit into from
Jan 18, 2024
Merged
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
33 changes: 30 additions & 3 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ def zlib_environment(tmp_path: Path):
return clone_test_dir("zlib", tmp_path).joinpath("environment.yml")


@pytest.fixture
def tzcode_environment(tmp_path: Path):
contents = """
channels:
- conda-forge
- nodefaults
dependencies:
- tzcode
"""
env = tmp_path / "environment.yml"
env.write_text(contents)
return env


@pytest.fixture
def input_hash_zlib_environment(tmp_path: Path):
return clone_test_dir("test-input-hash-zlib", tmp_path).joinpath("environment.yml")
Expand Down Expand Up @@ -1812,7 +1826,9 @@ def test_install(
kind: str,
tmp_path: Path,
conda_exe: str,
zlib_environment: Path,
# We choose tzcode since it depends on glibc on linux-64, and this induces a
# virtual package, and we test to make sure it's filtered out from the lockfile.
tzcode_environment: Path,
monkeypatch: "pytest.MonkeyPatch",
capsys: "pytest.CaptureFixture[str]",
):
Expand All @@ -1830,7 +1846,7 @@ def test_install(
generated_lockfile_path.mkdir(exist_ok=True)
monkeypatch.chdir(generated_lockfile_path)

package = "zlib"
package = "tzcode"
platform = "linux-64"

lock_filename_template = (
Expand All @@ -1852,7 +1868,7 @@ def test_install(
"-p",
platform,
"-f",
str(zlib_environment),
str(tzcode_environment),
"-k",
kind,
"--filename-template",
Expand All @@ -1866,6 +1882,17 @@ def test_install(
print(result.stderr, file=sys.stderr)
assert result.exit_code == 0

lockfile_content = Path(lock_filename).read_text()
if kind == "lock":
might_contain_virtual_package = "name: __" in lockfile_content
else:
might_contain_virtual_package = "__" in lockfile_content
assert not might_contain_virtual_package, (
f"Lockfile may contain a virtual package (e.g. __glibc). "
f"These should never appear in the lockfile. "
f"{lockfile_content}"
)

prefix = root_prefix / "test_env"

context: ContextManager
Expand Down