@@ -99,10 +99,11 @@ def _setup(self) -> None:
99
99
100
100
101
101
def execute_cmdline_scenarios (
102
- scenario_name : str | None ,
102
+ scenario_names : list [ str ] | None ,
103
103
args : MoleculeArgs ,
104
104
command_args : CommandArgs ,
105
105
ansible_args : tuple [str , ...] = (),
106
+ excludes : list [str ] | None = None ,
106
107
) -> None :
107
108
"""Execute scenario sequences based on parsed command-line arguments.
108
109
@@ -113,28 +114,33 @@ def execute_cmdline_scenarios(
113
114
to generate the scenario(s) configuration.
114
115
115
116
Args:
116
- scenario_name : Name of scenario to run, or ``None`` to run all.
117
+ scenario_names : Name of scenarios to run, or ``None`` to run all.
117
118
args: ``args`` dict from ``click`` command context
118
119
command_args: dict of command arguments, including the target
119
120
ansible_args: Optional tuple of arguments to pass to the `ansible-playbook` command
121
+ excludes: Name of scenarios to not run.
120
122
121
123
Raises:
122
124
SystemExit: If scenario exits prematurely.
123
125
"""
124
- glob_str = MOLECULE_GLOB
125
- if scenario_name :
126
- glob_str = glob_str .replace ("*" , scenario_name )
127
- scenarios = molecule .scenarios .Scenarios (
128
- get_configs (args , command_args , ansible_args , glob_str ),
129
- scenario_name ,
130
- )
126
+ if excludes is None :
127
+ excludes = []
128
+
129
+ configs : list [config .Config ] = []
130
+ if scenario_names is None :
131
+ configs = [
132
+ config
133
+ for config in get_configs (args , command_args , ansible_args , MOLECULE_GLOB )
134
+ if config .scenario .name not in excludes
135
+ ]
136
+ else :
137
+ # filter out excludes
138
+ scenario_names = [name for name in scenario_names if name not in excludes ]
139
+ for scenario_name in scenario_names :
140
+ glob_str = MOLECULE_GLOB .replace ("*" , scenario_name )
141
+ configs .extend (get_configs (args , command_args , ansible_args , glob_str ))
131
142
132
- if scenario_name and scenarios :
133
- LOG .info (
134
- "%s scenario test matrix: %s" ,
135
- scenario_name ,
136
- ", " .join (scenarios .sequence (scenario_name )),
137
- )
143
+ scenarios = _generate_scenarios (scenario_names , configs )
138
144
139
145
for scenario in scenarios :
140
146
if scenario .config .config ["prerun" ]:
@@ -171,6 +177,36 @@ def execute_cmdline_scenarios(
171
177
raise
172
178
173
179
180
+ def _generate_scenarios (
181
+ scenario_names : list [str ] | None ,
182
+ configs : list [config .Config ],
183
+ ) -> molecule .scenarios .Scenarios :
184
+ """Generate Scenarios object from names and configs.
185
+
186
+ Args:
187
+ scenario_names: Names of scenarios to include.
188
+ configs: List of Config objects to consider.
189
+
190
+ Returns:
191
+ Combined Scenarios object.
192
+ """
193
+ scenarios = molecule .scenarios .Scenarios (
194
+ configs ,
195
+ scenario_names ,
196
+ )
197
+
198
+ if scenario_names is not None :
199
+ for scenario_name in scenario_names :
200
+ if scenario_name != "*" and scenarios :
201
+ LOG .info (
202
+ "%s scenario test matrix: %s" ,
203
+ scenario_name ,
204
+ ", " .join (scenarios .sequence (scenario_name )),
205
+ )
206
+
207
+ return scenarios
208
+
209
+
174
210
def execute_subcommand (
175
211
current_config : config .Config ,
176
212
subcommand_and_args : str ,
0 commit comments