@@ -51,12 +51,11 @@ def before_feature(context, feature):
51
51
severity = OutcomeSeverity .ERROR ,
52
52
)
53
53
context .protocol_errors .append (validation_outcome )
54
+
55
+ context .gherkin_outcomes = context .protocol_errors
54
56
55
57
56
58
def before_scenario (context , scenario ):
57
- context .gherkin_outcomes = []
58
- for protocol_error in context .protocol_errors :
59
- context .gherkin_outcomes .append (protocol_error )
60
59
context .applicable = True
61
60
62
61
def before_step (context , step ):
@@ -68,9 +67,14 @@ def get_validation_outcome_hash(obj):
68
67
def after_scenario (context , scenario ):
69
68
# Given steps may introduce an arbitrary amount of stackframes.
70
69
# we need to clean them up before behave starts appending new ones.
70
+ old_outcomes = getattr (context , 'gherkin_outcomes' , [])
71
71
while context ._stack [0 ].get ('@layer' ) == 'attribute' :
72
72
context ._pop ()
73
+ # preserve the outcomes to be serialized to DB in after_feature()
74
+ context .gherkin_outcomes = old_outcomes
75
+
73
76
77
+ def after_feature (context , feature ):
74
78
execution_mode = context .config .userdata .get ('execution_mode' )
75
79
if execution_mode and execution_mode == 'ExecutionMode.PRODUCTION' : # DB interaction only needed during production run, not in testing
76
80
from validation_results import OutcomeSeverity , ModelInstance , ValidationTask
@@ -81,20 +85,15 @@ def reduce_db_outcomes(feature_outcomes):
81
85
if failed_outcomes :
82
86
unique_outcomes = set () # TODO __hash__ + __eq__ will be better
83
87
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
86
89
else :
87
90
outcome_counts = Counter (outcome .severity for outcome in context .gherkin_outcomes )
88
-
89
91
for severity in [OutcomeSeverity .PASSED , OutcomeSeverity .EXECUTED , OutcomeSeverity .NOT_APPLICABLE ]:
90
92
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
96
95
97
- outcomes_to_save = reduce_db_outcomes (context .gherkin_outcomes )
96
+ outcomes_to_save = list ( reduce_db_outcomes (context .gherkin_outcomes ) )
98
97
99
98
if outcomes_to_save and context .validation_task_id is not None :
100
99
retrieved_task = ValidationTask .objects .get (id = context .validation_task_id )
0 commit comments