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: warn user when first argument to session.run is a list #786

Merged
merged 3 commits into from
Feb 29, 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
4 changes: 4 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ def run(
if not args:
raise ValueError("At least one argument required to run().")

if len(args) == 1 and isinstance(args[0], (list, tuple)):
msg = "First argument to `session.run` is a list. Did you mean to use `session.run(*args)`?"
raise ValueError(msg)

if self._runner.global_config.install_only:
logger.info(f"Skipping {args[0]} run, as --install-only is set.")
return None
Expand Down
6 changes: 6 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ def test___dict__(self):
expected = {name: getattr(session, name) for name in session.__slots__}
assert session.__dict__ == expected

def test_first_arg_list(self):
session, _ = self.make_session_and_runner()

with pytest.raises(ValueError):
session.run(["ls", "-al"])


class TestSessionRunner:
def make_runner(self):
Expand Down