From 5abd6fc5d829e6aa2c93f07c38897cbaf14f04c9 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 28 Feb 2024 11:58:56 -0800 Subject: [PATCH 1/3] feat: warn user when first argument to session.run is a list They probably meant to unpack the list. --- nox/sessions.py | 4 ++++ tests/test_sessions.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/nox/sessions.py b/nox/sessions.py index a98916f4..b6baf4f8 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -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): + raise ValueError("First argument to `session.run` is a list. " + "Did you mean to use `session.run(*args)`?") + if self._runner.global_config.install_only: logger.info(f"Skipping {args[0]} run, as --install-only is set.") return None diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 24ebd635..3b8c53d6 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -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): From 847e11ebba154cb31e3d22f7e2152e3d53fd22b8 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 28 Feb 2024 13:12:53 -0800 Subject: [PATCH 2/3] Add tuple check on Henry's suggestion Co-authored-by: Henry Schreiner --- nox/sessions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nox/sessions.py b/nox/sessions.py index b6baf4f8..71bd2e9e 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -379,7 +379,7 @@ def run( if not args: raise ValueError("At least one argument required to run().") - if len(args) == 1 and isinstance(args[0], list): + if len(args) == 1 and isinstance(args[0], (list, tuple)): raise ValueError("First argument to `session.run` is a list. " "Did you mean to use `session.run(*args)`?") From 3fa17eed7c19e45e8db55aab51221cea571d27fd Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 28 Feb 2024 13:42:39 -0800 Subject: [PATCH 3/3] Raise ValueError from assigned variable Co-authored-by: Henry Schreiner --- nox/sessions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nox/sessions.py b/nox/sessions.py index 71bd2e9e..1ecacf04 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -380,8 +380,8 @@ def run( raise ValueError("At least one argument required to run().") if len(args) == 1 and isinstance(args[0], (list, tuple)): - raise ValueError("First argument to `session.run` is a list. " - "Did you mean to use `session.run(*args)`?") + 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.")