Skip to content

Commit 5f85ebd

Browse files
authored
Merge pull request #271 from buildingSMART/IVS117_outcome_massaging
IVS-117 outcome massaging
2 parents aef5e4a + e460dad commit 5f85ebd

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

features/environment.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ def before_feature(context, feature):
5151
severity=OutcomeSeverity.ERROR,
5252
)
5353
context.protocol_errors.append(validation_outcome)
54+
55+
context.gherkin_outcomes = context.protocol_errors
5456

5557

5658
def before_scenario(context, scenario):
57-
context.gherkin_outcomes = []
58-
for protocol_error in context.protocol_errors:
59-
context.gherkin_outcomes.append(protocol_error)
6059
context.applicable = True
6160

6261
def before_step(context, step):
@@ -68,9 +67,14 @@ def get_validation_outcome_hash(obj):
6867
def after_scenario(context, scenario):
6968
# Given steps may introduce an arbitrary amount of stackframes.
7069
# we need to clean them up before behave starts appending new ones.
70+
old_outcomes = getattr(context, 'gherkin_outcomes', [])
7171
while context._stack[0].get('@layer') == 'attribute':
7272
context._pop()
73+
# preserve the outcomes to be serialized to DB in after_feature()
74+
context.gherkin_outcomes = old_outcomes
75+
7376

77+
def after_feature(context, feature):
7478
execution_mode = context.config.userdata.get('execution_mode')
7579
if execution_mode and execution_mode == 'ExecutionMode.PRODUCTION': # DB interaction only needed during production run, not in testing
7680
from validation_results import OutcomeSeverity, ModelInstance, ValidationTask
@@ -81,20 +85,15 @@ def reduce_db_outcomes(feature_outcomes):
8185
if failed_outcomes:
8286
unique_outcomes = set() # TODO __hash__ + __eq__ will be better
8387
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)]
84-
return unique_objects
85-
88+
yield from unique_objects
8689
else:
8790
outcome_counts = Counter(outcome.severity for outcome in context.gherkin_outcomes)
88-
8991
for severity in [OutcomeSeverity.PASSED, OutcomeSeverity.EXECUTED, OutcomeSeverity.NOT_APPLICABLE]:
9092
if outcome_counts[severity] > 0:
91-
for outcome in context.gherkin_outcomes:
92-
if outcome.severity == severity:
93-
return [outcome]
94-
95-
return []
93+
yield next(outcome for outcome in context.gherkin_outcomes if outcome.severity == severity)
94+
break
9695

97-
outcomes_to_save = reduce_db_outcomes(context.gherkin_outcomes)
96+
outcomes_to_save = list(reduce_db_outcomes(context.gherkin_outcomes))
9897

9998
if outcomes_to_save and context.validation_task_id is not None:
10099
retrieved_task = ValidationTask.objects.get(id=context.validation_task_id)

0 commit comments

Comments
 (0)