Skip to content

Commit 547fe48

Browse files
committed
[uss_qualifier] Add filter option when runnign tests
1 parent b1322fa commit 547fe48

File tree

5 files changed

+58
-68
lines changed

5 files changed

+58
-68
lines changed

.basedpyright/baseline.json

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5191,46 +5191,6 @@
51915191
"lineCount": 1
51925192
}
51935193
},
5194-
{
5195-
"code": "reportOperatorIssue",
5196-
"range": {
5197-
"startColumn": 8,
5198-
"endColumn": 29,
5199-
"lineCount": 1
5200-
}
5201-
},
5202-
{
5203-
"code": "reportOptionalMemberAccess",
5204-
"range": {
5205-
"startColumn": 19,
5206-
"endColumn": 28,
5207-
"lineCount": 1
5208-
}
5209-
},
5210-
{
5211-
"code": "reportOptionalMemberAccess",
5212-
"range": {
5213-
"startColumn": 55,
5214-
"endColumn": 64,
5215-
"lineCount": 1
5216-
}
5217-
},
5218-
{
5219-
"code": "reportOptionalMemberAccess",
5220-
"range": {
5221-
"startColumn": 19,
5222-
"endColumn": 28,
5223-
"lineCount": 1
5224-
}
5225-
},
5226-
{
5227-
"code": "reportOptionalMemberAccess",
5228-
"range": {
5229-
"startColumn": 15,
5230-
"endColumn": 24,
5231-
"lineCount": 1
5232-
}
5233-
},
52345194
{
52355195
"code": "reportArgumentType",
52365196
"range": {
@@ -5239,30 +5199,6 @@
52395199
"lineCount": 1
52405200
}
52415201
},
5242-
{
5243-
"code": "reportOptionalMemberAccess",
5244-
"range": {
5245-
"startColumn": 38,
5246-
"endColumn": 47,
5247-
"lineCount": 1
5248-
}
5249-
},
5250-
{
5251-
"code": "reportOperatorIssue",
5252-
"range": {
5253-
"startColumn": 51,
5254-
"endColumn": 72,
5255-
"lineCount": 1
5256-
}
5257-
},
5258-
{
5259-
"code": "reportOptionalMemberAccess",
5260-
"range": {
5261-
"startColumn": 36,
5262-
"endColumn": 42,
5263-
"lineCount": 1
5264-
}
5265-
},
52665202
{
52675203
"code": "reportOptionalSubscript",
52685204
"range": {

monitoring/uss_qualifier/configurations/configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class ExecutionConfiguration(ImplicitDict):
132132
stop_when_resource_not_created: bool | None = False
133133
"""If true, stop test execution if one of the resources cannot be created. Otherwise, resources that cannot be created due to missing prerequisites are simply treated as omitted."""
134134

135+
scenarios_filter: str | None
136+
"""Filter test scenarios by class name using a regex. When empty, all scenarios are executed. Useful for targeted debugging. Overridden by --filter"""
137+
135138

136139
class TestConfiguration(ImplicitDict):
137140
action: TestSuiteActionDeclaration

monitoring/uss_qualifier/main.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from monitoring.monitorlib.dicts import get_element_or_default, remove_elements
1313
from monitoring.monitorlib.versioning import get_code_version, get_commit_hash
1414
from monitoring.uss_qualifier.configurations.configuration import (
15+
ExecutionConfiguration,
16+
TestConfiguration,
1517
USSQualifierConfiguration,
1618
USSQualifierConfigurationV1,
1719
)
@@ -79,6 +81,12 @@ def parseArgs() -> argparse.Namespace:
7981
help="When true, do not run a test configuration which would produce unredacted sensitive information in its artifacts",
8082
)
8183

84+
parser.add_argument(
85+
"--filter",
86+
default=None,
87+
help="Filter test scenarios by class name using a regex. When empty, all scenarios are executed. Useful for targeted debugging.",
88+
)
89+
8290
return parser.parse_args()
8391

8492

@@ -101,18 +109,20 @@ def sign(self, whole_config: USSQualifierConfiguration) -> None:
101109
baseline = whole_config
102110
environment = []
103111
self.baseline_signature = compute_baseline_signature(
104-
self.codebase_version,
105-
self.commit_hash,
106-
compute_signature(baseline),
112+
self.codebase_version, self.commit_hash, compute_signature(baseline)
107113
)
108114
self.environment_signature = compute_signature(environment)
109115

110116

111117
def execute_test_run(
112-
whole_config: USSQualifierConfiguration, description: TestDefinitionDescription
118+
whole_config: USSQualifierConfiguration,
119+
description: TestDefinitionDescription,
113120
):
114121
config = whole_config.v1.test_run
115122

123+
if not config:
124+
raise ValueError("v1.test_run not defined in configuration")
125+
116126
logger.info("Instantiating resources")
117127
stop_when_not_created = (
118128
"execution" in config
@@ -172,6 +182,7 @@ def run_config(
172182
output_path: str | None,
173183
runtime_metadata: dict | None,
174184
disallow_unredacted: bool,
185+
scenarios_filter: str | None,
175186
):
176187
config_src = load_dict_with_references(config_name)
177188

@@ -187,6 +198,21 @@ def run_config(
187198

188199
whole_config = ImplicitDict.parse(config_src, USSQualifierConfiguration)
189200

201+
if scenarios_filter:
202+
# We set the scenario filter in the test run execution's object
203+
# As parameters are optional, we ensure they do exist first
204+
205+
if "v1" not in whole_config or not whole_config.v1:
206+
whole_config.v1 = USSQualifierConfigurationV1()
207+
if "test_run" not in whole_config.v1 or not whole_config.v1.test_run:
208+
whole_config.v1.test_run = TestConfiguration()
209+
if (
210+
"execution" not in whole_config.v1.test_run
211+
or not whole_config.v1.test_run.execution
212+
):
213+
whole_config.v1.test_run.execution = ExecutionConfiguration()
214+
whole_config.v1.test_run.execution.scenarios_filter = scenarios_filter
215+
190216
if config_output:
191217
logger.info("Writing flattened configuration to {}", config_output)
192218
if config_output.lower().endswith(".json"):
@@ -257,6 +283,7 @@ def main() -> int:
257283
raise ValueError("--runtime-metadata must specify a JSON dictionary")
258284

259285
disallow_unredacted = args.disallow_unredacted
286+
scenarios_filter = args.filter
260287

261288
config_names = str(args.config).split(",")
262289

@@ -285,6 +312,7 @@ def main() -> int:
285312
output_path,
286313
runtime_metadata,
287314
disallow_unredacted,
315+
scenarios_filter,
288316
)
289317
if exit_code != os.EX_OK:
290318
return exit_code

monitoring/uss_qualifier/suites/suite.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def _run_test_scenario(self, context: ExecutionContext) -> TestScenarioReport:
158158
scenario.time_context[TimeDuringTest.StartOfScenario] = Time(
159159
arrow.utcnow().datetime
160160
)
161+
161162
try:
162163
try:
163164
scenario.run(context)
@@ -630,6 +631,21 @@ def evaluate_skip(self) -> SkippedActionReport | None:
630631
declaration=self.current_frame.action.declaration,
631632
)
632633

634+
if (
635+
"scenarios_filter" in self.config
636+
and self.config.scenarios_filter
637+
and self.current_frame.action.test_scenario
638+
):
639+
if not re.match(
640+
self.config.scenarios_filter,
641+
self.current_frame.action.test_scenario.__class__.__name__,
642+
):
643+
return SkippedActionReport(
644+
timestamp=StringBasedDateTime(arrow.utcnow()),
645+
reason="Filtered scenario",
646+
declaration=self.current_frame.action.declaration,
647+
)
648+
633649
return None
634650

635651
def begin_action(self, action: TestSuiteAction) -> None:

schemas/monitoring/uss_qualifier/configurations/configuration/ExecutionConfiguration.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
"null"
1818
]
1919
},
20+
"scenarios_filter": {
21+
"description": "Filter test scenarios by class name using a regex. When empty, all scenarios are executed. Useful for targeted debugging. Overridden by --filter",
22+
"type": [
23+
"string",
24+
"null"
25+
]
26+
},
2027
"skip_action_when": {
2128
"description": "If specified, do not execute test actions if they are selected by ANY of these conditions.",
2229
"items": {

0 commit comments

Comments
 (0)