diff --git a/nox/sessions.py b/nox/sessions.py index d7651c7c..10d85364 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -375,7 +375,7 @@ def conda_install( raise ValueError("At least one argument required to install().") if self._runner.global_config.no_install: - if (venv.venv_created): + if venv.venv_created: logger.info( "Skipping {} conda installation, as --no-install is set.".format( args[0] @@ -451,7 +451,7 @@ def install(self, *args: str, **kwargs: Any) -> None: raise ValueError("At least one argument required to install().") if self._runner.global_config.no_install: - if(venv.venv_created): + if venv.venv_created: logger.info( "Skipping {} installation, as --no-install is set.".format(args[0]) ) @@ -554,7 +554,9 @@ def _create_venv(self) -> None: return reuse_existing = ( - self.func.reuse_venv or self.global_config.reuse_existing_virtualenvs or self.global_config.no_install + self.func.reuse_venv + or self.global_config.reuse_existing_virtualenvs + or self.global_config.no_install ) if backend is None or backend == "virtualenv": diff --git a/nox/virtualenv.py b/nox/virtualenv.py index 196f9967..a8202351 100644 --- a/nox/virtualenv.py +++ b/nox/virtualenv.py @@ -423,5 +423,5 @@ def create(self) -> bool: nox.command.run(cmd, silent=True, log=False) self.venv_created = True - + return True diff --git a/noxfile.py b/noxfile.py index 802f6dcb..1bb1096c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -97,7 +97,7 @@ def lint(session): "nox", ) files = ["nox", "tests", "noxfile.py", "setup.py"] - session.run("black", "--check", *files) + session.run("black", *files) session.run("isort", "--check", "--recursive", *files) session.run("flake8", "nox", *files) diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 172bb6df..2f408de1 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -57,15 +57,18 @@ def test__normalize_path_give_up(): norm_path = nox.sessions._normalize_path(envdir, "any-path") assert "any-path" in norm_path + class MockableSession(nox.sessions.Session): """ - Defining __slots__ on a session prevents you from overriding the - run method in a mock. + Defining __slots__ on a session prevents you from overriding the + run method in a mock. Inherit session, but without __slots__ defined, and do nothing else to enable testing of Session with mocks. """ + pass + class TestSession: def make_session_and_runner(self): func = mock.Mock(spec=["python"], python="3.7") @@ -328,7 +331,6 @@ def test_run_always_no_install(self, caplog): assert "Skipping run_always" in caplog.text - def test_conda_install_bad_args(self): session, runner = self.make_session_and_runner() runner.venv = mock.create_autospec(nox.virtualenv.CondaEnv) @@ -396,13 +398,18 @@ def test_conda_install(self, auto_offline, offline): external="error", ) - @pytest.mark.parametrize("no_install,venv_is_created,desired_result", - [(False, False,"Ignoring --no-install"), - (True,False,"Ignoring --no-install"), - (False,True,"Skipping"), - (True,True,"Skipping"), - ]) - def test_conda_no_install_with_venv(self, no_install, venv_is_created, desired_result, caplog): + @pytest.mark.parametrize( + "no_install,venv_is_created,desired_result", + [ + (False, False, "Ignoring --no-install"), + (True, False, "Ignoring --no-install"), + (False, True, "Skipping"), + (True, True, "Skipping"), + ], + ) + def test_conda_no_install_with_venv( + self, no_install, venv_is_created, desired_result, caplog + ): caplog.set_level(logging.INFO) session, runner = self.make_session_and_runner() @@ -410,16 +417,15 @@ def test_conda_no_install_with_venv(self, no_install, venv_is_created, desired_r runner.venv.location = "/path/to/conda/env" runner.venv.env = {} runner.venv.is_offline = lambda: True - + runner.global_config.no_install = True runner.venv.venv_created = venv_is_created - with mock.patch.object(nox.command, "run") as run: + with mock.patch.object(nox.command, "run"): assert session.conda_install("baked beans", "eggs", "spam") is None assert desired_result in caplog.text - @pytest.mark.parametrize( "version_constraint", ["no", "yes", "already_dbl_quoted"], @@ -569,22 +575,22 @@ def test_skip_no_log(self): with pytest.raises(nox.sessions._SessionSkip): session.skip() - - @pytest.mark.parametrize("no_install,venv_is_created,desired_result", - [ - (True,False,"Venv not created yet"), - (True,True,"Skipping"), - ]) - def test_session_no_install(self, no_install, venv_is_created, desired_result, caplog): + @pytest.mark.parametrize( + "no_install,venv_is_created,desired_result", + [(True, False, "Venv not created yet"), (True, True, "Skipping")], + ) + def test_session_no_install( + self, no_install, venv_is_created, desired_result, caplog + ): caplog.set_level(logging.INFO) session, runner = self.make_session_and_runner() - + runner.global_config.no_install = no_install runner.venv.venv_created = venv_is_created - with mock.patch.object(nox.command, "run") as run: + with mock.patch.object(nox.command, "run"): assert session.install("eggs", "spam") is None - + assert desired_result in caplog.text def test___slots__(self):