diff --git a/nox/sessions.py b/nox/sessions.py index 42f0a4f0..3cb838c1 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -22,7 +22,6 @@ import re import sys import unicodedata -import warnings from types import TracebackType from typing import Any, Callable, Iterable, Mapping, Sequence @@ -533,6 +532,12 @@ def install(self, *args: str, **kwargs: Any) -> None: Additional keyword args are the same as for :meth:`run`. + .. warning:: + + Running ``session.install`` without a virtual environment + is no longer supported. If you still want to do that, please + use ``session.run("pip", "install", ...)`` instead. + .. _pip: https://pip.readthedocs.org """ venv = self._runner.venv @@ -544,13 +549,11 @@ def install(self, *args: str, **kwargs: Any) -> None: "A session without a virtualenv can not install dependencies." ) if isinstance(venv, PassthroughEnv): - warnings.warn( - f"Session {self.name} does not have a virtual environment, " - "so use of session.install() is deprecated since it would modify " - "the global Python environment. If you're really sure that is " - 'what you want to do, use session.run("pip", "install", ...) instead.', - category=FutureWarning, - stacklevel=2, + raise ValueError( + f"Session {self.name} does not have a virtual environment, so use of" + " session.install() is no longer allowed since it would modify the" + " global Python environment. If you're really sure that is what you" + ' want to do, use session.run("pip", "install", ...) instead.' ) if not args: raise ValueError("At least one argument required to install().") diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 688b8f18..f7535958 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -646,7 +646,7 @@ class SessionNoSlots(nox.sessions.Session): external="error", ) - def test_install_no_venv_deprecated(self): + def test_install_no_venv_failure(self): runner = nox.sessions.SessionRunner( name="test", signatures=["test"], @@ -662,25 +662,14 @@ class SessionNoSlots(nox.sessions.Session): session = SessionNoSlots(runner=runner) - with mock.patch.object(session, "_run", autospec=True) as run: - with pytest.warns( - FutureWarning, - match=( - r"use of session\.install\(\) is deprecated since it would modify" - r" the global Python environment" - ), - ): - session.install("requests", "urllib3") - run.assert_called_once_with( - "python", - "-m", - "pip", - "install", - "requests", - "urllib3", - silent=True, - external="error", - ) + with pytest.raises( + ValueError, + match=( + r"use of session\.install\(\) is no longer allowed since" + r" it would modify the global Python environment" + ), + ): + session.install("requests", "urllib3") def test_notify(self): session, runner = self.make_session_and_runner()