From d9418e98b7e8b7472fc734274173adefadd499c6 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Mon, 9 Nov 2020 09:45:06 +0100 Subject: [PATCH] Do not merge command-line options in place When merging options specified in the noxfile and on the command-line option, do not use the output parameter `command_args` as the input for the merge; instead, copy `command_args` initially and pass the copy to the merge functions. Merge functions such as `_session_filters_merge_func` inspect `command_args` to see if other options have been specified on the command-line. When the options are merged in place, this check produces false positives. For example, `nox.options.sessions` is copied into `command_args` as a part of the merge; so it will appear to have been specified on the command-line when merging `nox.options.pythons`, causing the latter to be ignored. --- nox/_option_set.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nox/_option_set.py b/nox/_option_set.py index 0c91e9cc..4bcbb357 100644 --- a/nox/_option_set.py +++ b/nox/_option_set.py @@ -304,13 +304,16 @@ def merge_namespaces( self, command_args: Namespace, noxfile_args: Namespace ) -> None: """Merges the command-line options with the noxfile options.""" + command_args_copy = Namespace(**vars(command_args)) for name, option in self.options.items(): if option.merge_func: setattr( - command_args, name, option.merge_func(command_args, noxfile_args) + command_args, + name, + option.merge_func(command_args_copy, noxfile_args), ) elif option.noxfile: - value = getattr(command_args, name, None) or getattr( + value = getattr(command_args_copy, name, None) or getattr( noxfile_args, name, None ) setattr(command_args, name, value)