Skip to content

Commit

Permalink
fix: make --tags behave like --sessions and --keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed Jul 12, 2023
1 parent eef4e02 commit e0bd1e5
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 @@ -66,11 +66,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 @@ -80,7 +80,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 @@ -280,7 +284,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=default_env_var_list_factory("NOXSESSION"),
help="Which sessions to run. By default, all sessions will run.",
Expand All @@ -303,7 +307,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 @@ -312,6 +316,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 e0bd1e5

Please sign in to comment.