Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error if invalid reuse_venv set #872

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,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 @@ -1144,6 +1145,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
Loading