Skip to content

Commit

Permalink
fix: warn user when first argument to session.run is a list (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanv committed Feb 29, 2024
1 parent d59e1ac commit 1c6af24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit 1c6af24

Please sign in to comment.