Skip to content

Commit

Permalink
fix: error if invalid reuse_venv set (#872)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Oct 31, 2024
1 parent f2325f1 commit 6f3a459
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,12 @@ def reuse_existing_venv(self) -> bool:
Returns:
bool: True if the existing virtual environment should be reused, False otherwise.
"""
if self.global_config.reuse_venv not in {"always", "never", "no", "yes", None}:
msg = (
"nox.options.reuse_venv must be set to 'always', 'never', 'no', or 'yes',"
f" got {self.global_config.reuse_venv!r}!"
)
raise AttributeError(msg)

return any(
(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
import operator
import os
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -1145,6 +1146,13 @@ def test__reuse_venv_outcome(self, reuse_venv, reuse_venv_func, should_reuse):
runner.global_config.reuse_venv = reuse_venv
assert runner.reuse_existing_venv() == should_reuse

def test__reuse_venv_invalid(self):
runner = self.make_runner()
runner.global_config.reuse_venv = True
msg = "nox.options.reuse_venv must be set to 'always', 'never', 'no', or 'yes', got True!"
with pytest.raises(AttributeError, match=re.escape(msg)):
runner.reuse_existing_venv()

def make_runner_with_mock_venv(self):
runner = self.make_runner()
runner._create_venv = mock.Mock()
Expand Down

0 comments on commit 6f3a459

Please sign in to comment.