Skip to content

Commit

Permalink
feat: support setting an empty session list
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Dec 22, 2021
1 parent 8c017f5 commit 02ede6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/config.rst
Expand Up @@ -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 <opt-envdir>`.
* ``nox.options.sessions`` is equivalent to specifying :ref:`-s or --sessions <opt-sessions-pythons-and-keywords>`.
* ``nox.options.sessions`` is equivalent to specifying :ref:`-s or --sessions <opt-sessions-pythons-and-keywords>`. 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 <opt-sessions-pythons-and-keywords>`.
* ``nox.options.keywords`` is equivalent to specifying :ref:`-k or --keywords <opt-sessions-pythons-and-keywords>`.
* ``nox.options.default_venv_backend`` is equivalent to specifying :ref:`-db or --default-venv-backend <opt-default-venv-backend>`.
Expand Down
4 changes: 4 additions & 0 deletions nox/tasks.py
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_tasks.py
Expand Up @@ -346,6 +346,20 @@ 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)
Expand Down

0 comments on commit 02ede6f

Please sign in to comment.