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

Make tests use a temporary directory for conda environments #549

Merged
merged 2 commits into from
Aug 30, 2023

Conversation

asmeurer
Copy link
Contributor

Previously they used the current conda prefix, but this is dangerous (there's a risk a broken test could break the dev environment), and the current conda prefix could contain things that break the tests.

This currently works by parameterizing in the fixture itself (currently just for two basic envs, one without pip packages and one with). But in the future we can do this parameterization on a per-test level with indirect parameterization. See
https://docs.pytest.org/en/latest/example/parametrize.html#indirect-parametrization

Currently, the test_generate_conda_export() test fails here. The reason is that it creates an export which cannot actually be read by the CondaSpecification object.

The reason for this is that the "name" of the environment that gets generated is just the same as the "prefix". This fails a validation check, because the name is guarded by a regular expression that disallows paths.

However, this appears to be a bug in conda-store, or maybe even an architectural issue. The "name" of a conda environment, as defined by "conda env export" at least, is only really defined if that environment is in the envs directory. I checked, and even env export yamls generated by conda-store itself (in standalone mode) end up having the prefix for the name, rather than the supposed actual environment name.

At best, it means that this test is just wrong and it shouldn't actually check the generated YAML file by trying to load it into a CondaSpecification.

I don't know if conda actually stores the environment "name" anywhere in the environment. It seems to me that this data should be stored separately by conda-store, especially since the environment path for environments created by conda-store is not actually the same as the environment name (the path contains a hash).

This is related to issue #513.

Description

This pull request:

  • a
  • b
  • c

Pull request checklist

  • Did you test this change locally?
  • Did you update the documentaion (if required)?
  • Did you add/update relevant tests for this change (if required)?

Additional information

Previously they used the current conda prefix, but this is dangerous (there's
a risk a broken test could break the dev environment), and the current conda
prefix could contain things that break the tests.

This currently works by parameterizing in the fixture itself (currently just
for two basic envs, one without pip packages and one with). But in the future
we can do this parameterization on a per-test level with indirect
parameterization. See
https://docs.pytest.org/en/latest/example/parametrize.html#indirect-parametrization

Currently, the test_generate_conda_export() test fails here. The reason is
that it creates an export which cannot actually be read by the
CondaSpecification object.

The reason for this is that the "name" of the environment that gets generated
is just the same as the "prefix". This fails a validation check, because the
name is guarded by a regular expression that disallows paths.

However, this appears to be a bug in conda-store, or maybe even an
architectural issue. The "name" of a conda environment, as defined by "conda
env export" at least, is only really defined if that environment is in the
envs directory. I checked, and even env export yamls generated by conda-store
itself (in standalone mode) end up having the prefix for the name, rather than
the supposed actual environment name.

At best, it means that this test is just wrong and it shouldn't actually check
the generated YAML file by trying to load it into a CondaSpecification.

I don't know if conda actually stores the environment "name" anywhere in the
environment. It seems to me that this data should be stored separately by
conda-store, especially since the environment path for environments created by
conda-store is not actually the same as the environment name (the path
contains a hash).
asmeurer added a commit to asmeurer/conda-store that referenced this pull request Aug 25, 2023
This is built on conda-incubator#549 but
I've made in a separate PR because I'm not sure if there will be other issues
here and I don't want to block that PR on this (but at the same time, tests
won't pass on Mac without the changes from that PR).

See conda-incubator#513 and conda-incubator#507
@asmeurer asmeurer mentioned this pull request Aug 25, 2023
3 tasks
Copy link
Member

@costrouc costrouc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if conda actually stores the environment "name" anywhere in the environment. It seems to me that this data should be stored separately by conda-store, especially since the environment path for environments created by conda-store is not actually the same as the environment name (the path contains a hash).

Yeah like you said conda doesn't store the name anywhere.

It takes the envs_dir director and any folder in there is assumed to be the name. It is possible for there to be collisions in the environment names.

I chose that the CondaSpecification does not store the name since I felt this was redundant (already stored in the db) and did not influence the solve. I agree that we may want to revisit this later on how we store the actual environment specification.

I'm fine with this PR as is

@pytest.fixture
def current_prefix():
return pathlib.Path(os.environ["CONDA_PREFIX"])
@pytest.fixture(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. This is a great way I think to be able to test more complete environment in the future.

@asmeurer
Copy link
Contributor Author

Just to be clear, test_generate_conda_export fails in its current state. Should I just remove the line that tries to load the environment file into a CondaSpecification? I could also to other workarounds like hotfixing the name before loading it, which would still test that everything else loads fine.

@costrouc
Copy link
Member

At best, it means that this test is just wrong and it shouldn't actually check the generated YAML file by trying to load it into a CondaSpecification.

@asmeurer I think you are completely right.

I could also to other workarounds like hotfixing the name before loading it, which would still test that everything else loads fine.

Yeah I'd go this route just so that we can be sure that export is still generating valid environment yamls.

@asmeurer
Copy link
Contributor Author

OK, I've made that change.

The environment name produced by conda env export will not be the actual
"name" of the environment unless that environment is inside of a conda envs
directory. Otherwise it is just the prefix, which fails the CondaSpecification
validation for the name. We work around this by just hotfixing the name in the
test before parsing the result.
Copy link
Member

@costrouc costrouc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@costrouc costrouc merged commit 9bfc91f into conda-incubator:main Aug 30, 2023
7 checks passed
asmeurer added a commit to asmeurer/conda-store that referenced this pull request Aug 30, 2023
This is built on conda-incubator#549 but
I've made in a separate PR because I'm not sure if there will be other issues
here and I don't want to block that PR on this (but at the same time, tests
won't pass on Mac without the changes from that PR).

See conda-incubator#513 and conda-incubator#507
trallard pushed a commit that referenced this pull request Oct 9, 2023
* Add a macOS worker to the CI

This is built on #549 but
I've made in a separate PR because I'm not sure if there will be other issues
here and I don't want to block that PR on this (but at the same time, tests
won't pass on Mac without the changes from that PR).

See #513 and #507

* Trigger build

* Try not using mamba to fix macos CI

* Add a separate macos environment file without conda-docker

* Use the macos environment file for macos on CI

* Try using mamba on macos again

* Revert "Try using mamba on macos again"

This reverts commit 031574a.

* Install mamba in the dev environment

* Go back to using mamba but with the correct syntax this time

Revert "Revert "Try using mamba on macos again""

This reverts commit 6cf2877.

* Fix CI

Revert "Go back to using mamba but with the correct syntax this time"

This reverts commit b82c0c8.

* Only test docker on Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done 💪🏾
Development

Successfully merging this pull request may close these issues.

None yet

3 participants