Skip to content

Commit 11dac8c

Browse files
authored
fix: don't error if not installing to passthrough (#809)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 956f10c commit 11dac8c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

nox/sessions.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def conda_install(
565565
prefix_args: tuple[str, ...] = ()
566566
if isinstance(venv, CondaEnv):
567567
prefix_args = ("--prefix", venv.location)
568-
elif not isinstance(venv, PassthroughEnv): # pragma: no cover
568+
elif not isinstance(venv, PassthroughEnv):
569569
raise ValueError(
570570
"A session without a conda environment can not install dependencies"
571571
" from conda."
@@ -574,7 +574,9 @@ def conda_install(
574574
if not args:
575575
raise ValueError("At least one argument required to install().")
576576

577-
if self._runner.global_config.no_install and venv._reused:
577+
if self._runner.global_config.no_install and (
578+
isinstance(venv, PassthroughEnv) or venv._reused
579+
):
578580
return
579581

580582
# Escape args that should be (conda-specific; pip install does not need this)
@@ -648,6 +650,8 @@ def install(self, *args: str, **kwargs: Any) -> None:
648650
"A session without a virtualenv can not install dependencies."
649651
)
650652
if isinstance(venv, PassthroughEnv):
653+
if self._runner.global_config.no_install:
654+
return
651655
raise ValueError(
652656
f"Session {self.name} does not have a virtual environment, so use of"
653657
" session.install() is no longer allowed since it would modify the"

tests/test_sessions.py

+14
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ def test_run_install_bad_args(self):
374374
exc_args = exc_info.value.args
375375
assert exc_args == ("At least one argument required to run_install().",)
376376

377+
def test_run_no_install_passthrough(self):
378+
session, runner = self.make_session_and_runner()
379+
runner.venv = nox.virtualenv.PassthroughEnv()
380+
runner.global_config.no_install = True
381+
382+
session.install("numpy")
383+
session.conda_install("numpy")
384+
385+
def test_run_no_conda_install(self):
386+
session, runner = self.make_session_and_runner()
387+
388+
with pytest.raises(ValueError, match="A session without a conda"):
389+
session.conda_install("numpy")
390+
377391
def test_run_install_success(self):
378392
session, _ = self.make_session_and_runner()
379393

0 commit comments

Comments
 (0)