From b9f16d9fc6ae5d18d4f8f425e65baae8c950cae6 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 10 Sep 2024 17:28:49 +0200 Subject: [PATCH 1/2] IVS-117 outcome massaging --- features/environment.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/features/environment.py b/features/environment.py index 13e2c63d..8d8333c2 100644 --- a/features/environment.py +++ b/features/environment.py @@ -51,12 +51,11 @@ def before_feature(context, feature): severity=OutcomeSeverity.ERROR, ) context.protocol_errors.append(validation_outcome) + + context.gherkin_outcomes = context.protocol_errors def before_scenario(context, scenario): - context.gherkin_outcomes = [] - for protocol_error in context.protocol_errors: - context.gherkin_outcomes.append(protocol_error) context.applicable = True def before_step(context, step): @@ -68,9 +67,14 @@ def get_validation_outcome_hash(obj): def after_scenario(context, scenario): # Given steps may introduce an arbitrary amount of stackframes. # we need to clean them up before behave starts appending new ones. + old_outcomes = getattr(context, 'gherkin_outcomes', []) while context._stack[0].get('@layer') == 'attribute': context._pop() + # preserve the outcomes to be serialized to DB in after_feature() + context.gherkin_outcomes = old_outcomes + +def after_feature(context, feature): execution_mode = context.config.userdata.get('execution_mode') if execution_mode and execution_mode == 'ExecutionMode.PRODUCTION': # DB interaction only needed during production run, not in testing from validation_results import OutcomeSeverity, ModelInstance, ValidationTask @@ -81,20 +85,15 @@ def reduce_db_outcomes(feature_outcomes): if failed_outcomes: unique_outcomes = set() # TODO __hash__ + __eq__ will be better unique_objects = [obj for obj in failed_outcomes if get_validation_outcome_hash(obj) not in unique_outcomes and (unique_outcomes.add(get_validation_outcome_hash(obj)) or True)] - return unique_objects - + yield from unique_objects else: outcome_counts = Counter(outcome.severity for outcome in context.gherkin_outcomes) - for severity in [OutcomeSeverity.PASSED, OutcomeSeverity.EXECUTED, OutcomeSeverity.NOT_APPLICABLE]: if outcome_counts[severity] > 0: - for outcome in context.gherkin_outcomes: - if outcome.severity == severity: - return [outcome] - - return [] + yield next(o for o in context.gherkin_outcomes if o.severity == severity) + break - outcomes_to_save = reduce_db_outcomes(context.gherkin_outcomes) + outcomes_to_save = list(reduce_db_outcomes(context.gherkin_outcomes)) if outcomes_to_save and context.validation_task_id is not None: retrieved_task = ValidationTask.objects.get(id=context.validation_task_id) From e460dadc8863c854c9d88e238a3da711148a4847 Mon Sep 17 00:00:00 2001 From: Scott Lecher Date: Tue, 10 Sep 2024 13:50:41 -0400 Subject: [PATCH 2/2] minor change to expand variable name --- features/environment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/environment.py b/features/environment.py index 8d8333c2..9da93e50 100644 --- a/features/environment.py +++ b/features/environment.py @@ -90,7 +90,7 @@ def reduce_db_outcomes(feature_outcomes): outcome_counts = Counter(outcome.severity for outcome in context.gherkin_outcomes) for severity in [OutcomeSeverity.PASSED, OutcomeSeverity.EXECUTED, OutcomeSeverity.NOT_APPLICABLE]: if outcome_counts[severity] > 0: - yield next(o for o in context.gherkin_outcomes if o.severity == severity) + yield next(outcome for outcome in context.gherkin_outcomes if outcome.severity == severity) break outcomes_to_save = list(reduce_db_outcomes(context.gherkin_outcomes))