Skip to content

Commit

Permalink
Merge sessions and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed Jan 16, 2023
1 parent 1fe4414 commit c7d0f02
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
17 changes: 11 additions & 6 deletions nox/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
)


def _sessions_and_keywords_merge_func(
def _sessions_merge_func(
key: str, command_args: argparse.Namespace, noxfile_args: argparse.Namespace
) -> list[str]:
"""Only return the Noxfile value for sessions/keywords if neither sessions
or keywords are specified on the command-line.
"""Only return the Noxfile value for sessions/keywords if neither sessions,
keywords or tags are specified on the command-line.
Args:
key (str): This function is used for both the "sessions" and "keywords"
Expand All @@ -78,7 +78,11 @@ def _sessions_and_keywords_merge_func(
command-line.
noxfile_Args (_option_set.Namespace): The options specified in the
Noxfile."""
if not command_args.sessions and not command_args.keywords:
if (
not command_args.sessions
and not command_args.keywords
and not command_args.tags
):
return getattr(noxfile_args, key) # type: ignore[no-any-return]
return getattr(command_args, key) # type: ignore[no-any-return]

Expand Down Expand Up @@ -260,7 +264,7 @@ def _session_completer(
"--session",
group=options.groups["sessions"],
noxfile=True,
merge_func=functools.partial(_sessions_and_keywords_merge_func, "sessions"),
merge_func=functools.partial(_sessions_merge_func, "sessions"),
nargs="*",
default=_sessions_default,
help="Which sessions to run. By default, all sessions will run.",
Expand All @@ -282,7 +286,7 @@ def _session_completer(
"--keywords",
group=options.groups["sessions"],
noxfile=True,
merge_func=functools.partial(_sessions_and_keywords_merge_func, "keywords"),
merge_func=functools.partial(_sessions_merge_func, "keywords"),
help="Only run sessions that match the given expression.",
),
_option_set.Option(
Expand All @@ -291,6 +295,7 @@ def _session_completer(
"--tags",
group=options.groups["sessions"],
noxfile=True,
merge_func=functools.partial(_sessions_merge_func, "tags"),
nargs="*",
help="Only run sessions with the given tags.",
),
Expand Down
25 changes: 25 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,31 @@ def quux():
assert "Tag selection caused no sessions to be selected." in caplog.text


def test_merge_sessions_and_tags():
@nox.session(tags=["foobar"])
def test():
pass

@nox.session(tags=["foobar"])
def bar():
pass

config = _options.options.namespace(
noxfile=os.path.join(RESOURCES, "noxfile_options.py"),
sessions=None,
pythons=(),
posargs=[],
tags=["foobar"],
)

nox_module = tasks.load_nox_module(config)
tasks.merge_noxfile_options(nox_module, config)
manifest = Manifest({"test": test, "bar": bar}, config)
return_value = tasks.filter_manifest(manifest, config)
assert return_value is manifest
assert len(manifest) == 2


def test_honor_list_request_noop():
config = _options.options.namespace(list_sessions=False)
manifest = {"thing": mock.sentinel.THING}
Expand Down

0 comments on commit c7d0f02

Please sign in to comment.