From 8bb3286fd4629b46db96d7ee35e32e0e607aafc7 Mon Sep 17 00:00:00 2001 From: Tolker-KU <55140581+Tolker-KU@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:44:20 +0100 Subject: [PATCH] Set CONDA_PREFIX in CondaEnv (#538) --- nox/virtualenv.py | 2 +- tests/test_virtualenv.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/nox/virtualenv.py b/nox/virtualenv.py index 02a63e0e..19b265dd 100644 --- a/nox/virtualenv.py +++ b/nox/virtualenv.py @@ -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""" diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index 441eaa89..485e2128 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -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 @@ -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.+):") + + assert path_regex.search(output).group("env_dir") == dir_.strpath + + def test_constructor_defaults(make_one): venv, _ = make_one() assert venv.location