Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge sessions and tags #684

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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