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

Fix current Conda env detection #538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion nox/virtualenv.py
Expand Up @@ -203,7 +203,7 @@ def __init__(
self.reuse_existing = reuse_existing
self.venv_params = venv_params if venv_params else []
self.conda_cmd = conda_cmd
super().__init__()
super().__init__(env={"CONDA_PREFIX": self.location})

def _clean_location(self) -> bool:
"""Deletes existing conda environment"""
Expand Down
20 changes: 20 additions & 0 deletions tests/test_virtualenv.py
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

import os
import re
import shutil
import subprocess
import sys
from textwrap import dedent
from unittest import mock
Expand Down Expand Up @@ -246,6 +248,24 @@ def test_condaenv_(make_conda):
assert not venv.is_offline()


@pytest.mark.skipif(not HAS_CONDA, reason="Missing conda command.")
def test_condaenv_detection(make_conda):
venv, dir_ = make_conda()
venv.create()

proc_result = subprocess.run(
[py.path.local.sysfind("conda").strpath, "list"],
env=venv.env,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
output = proc_result.stdout.decode()
path_regex = re.compile(r"packages in environment at (?P<env_dir>.+):")

assert path_regex.search(output).group("env_dir") == dir_.strpath


def test_constructor_defaults(make_one):
venv, _ = make_one()
assert venv.location
Expand Down