From 32eba77f26bc2589c130508a2aa855487abdc9ce Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 22 Dec 2021 15:04:43 -0500 Subject: [PATCH] feat: support setting an empty session list --- docs/config.rst | 2 +- nox/tasks.py | 4 ++++ tests/test_tasks.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/config.rst b/docs/config.rst index f3bb1b9d..f41d6ac1 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -418,7 +418,7 @@ Or, if you wanted to provide a set of sessions that are run by default: The following options can be specified in the Noxfile: * ``nox.options.envdir`` is equivalent to specifying :ref:`--envdir `. -* ``nox.options.sessions`` is equivalent to specifying :ref:`-s or --sessions `. +* ``nox.options.sessions`` is equivalent to specifying :ref:`-s or --sessions `. If set to an empty list, no sessions will be run if no sessions were given on the commend line, and the list of available sessions will be shown instead. * ``nox.options.pythons`` is equivalent to specifying :ref:`-p or --pythons `. * ``nox.options.keywords`` is equivalent to specifying :ref:`-k or --keywords `. * ``nox.options.default_venv_backend`` is equivalent to specifying :ref:`-db or --default-venv-backend `. diff --git a/nox/tasks.py b/nox/tasks.py index e237e4d3..6fab5a2e 100644 --- a/nox/tasks.py +++ b/nox/tasks.py @@ -179,6 +179,10 @@ def filter_manifest( logger.error("Error while collecting sessions.") logger.error(exc.args[0]) return 3 + elif global_config.sessions is not None: + # If the user did not specify sessions, and the noxfile is set + # to an empty list, then list the sessions instead. + global_config.list_sessions = True # Filter by python interpreter versions. # This function never errors, but may cause an empty list of sessions diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 2df4cfd5..3ea5693f 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -346,6 +346,21 @@ def test_honor_list_request_doesnt_print_docstring_if_not_present(capsys): assert "Hello I'm a docstring" not in out +def test_emtpy_session_list_in_noxfile(): + config = _options.options.namespace(noxfile="noxfile.py", sessions=()) + manifest = Manifest({}, config) + tasks.filter_manifest(manifest, global_config=config) + assert config.list_sessions + + +def test_emtpy_session_None_in_noxfile(): + config = _options.options.namespace(noxfile="noxfile.py", sessions=None) + manifest = Manifest({}, config) + tasks.filter_manifest(manifest, global_config=config) + assert not config.list_sessions + + + def test_verify_manifest_empty(): config = _options.options.namespace(sessions=(), keywords=()) manifest = Manifest({}, config)