Skip to content

Commit e803ae6

Browse files
committed
fixup! Add evaluation details to finally hook stage #403
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
1 parent d0d74cf commit e803ae6

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

openfeature/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,13 @@ def evaluate_flag_details( # noqa: PLR0915
393393
return flag_evaluation
394394

395395
finally:
396-
after_all_hooks(flag_type, hook_context, flag_evaluation, reversed_merged_hooks, hook_hints)
396+
after_all_hooks(
397+
flag_type,
398+
hook_context,
399+
flag_evaluation,
400+
reversed_merged_hooks,
401+
hook_hints
402+
)
397403

398404
def _create_provider_evaluation(
399405
self,

openfeature/hook/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ def error(
109109
"""
110110
pass
111111

112-
def finally_after(self, hook_context: HookContext, details: FlagEvaluationDetails[typing.Any], hints: HookHints) -> None:
112+
def finally_after(
113+
self,
114+
hook_context: HookContext,
115+
details: FlagEvaluationDetails[typing.Any],
116+
hints: HookHints
117+
) -> None:
113118
"""
114119
Run after flag evaluation, including any error processing.
115120
This will always run. Errors will be swallowed.

tests/features/steps/hooks_steps.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from openfeature.hook import Hook
77

88

9-
@when("a hook is added to the client")
10-
def step_impl(context):
9+
@when('a hook is added to the client')
10+
def step_impl_add_hook(context):
1111
hook = MagicMock(spec=Hook)
1212
hook.before = MagicMock()
1313
hook.after = MagicMock()
@@ -18,34 +18,34 @@ def step_impl(context):
1818

1919

2020
@then('error hooks should be called')
21-
def step_impl(context):
21+
def step_impl_call_error(context):
2222
assert context.hook.before.called
2323
assert context.hook.error.called
2424
assert context.hook.finally_after.called
2525

2626

2727
@then('non-error hooks should be called')
28-
def step_impl(context):
28+
def step_impl_call_non_error(context):
2929
assert context.hook.before.called
3030
assert context.hook.after.called
3131
assert context.hook.finally_after.called
3232

3333

3434
def get_hook_from_name(context, hook_name):
35-
if hook_name.lower() == "before":
35+
if hook_name.lower() == 'before':
3636
return context.hook.before
37-
elif hook_name.lower() == "after":
37+
elif hook_name.lower() == 'after':
3838
return context.hook.after
39-
elif hook_name.lower() == "error":
39+
elif hook_name.lower() == 'error':
4040
return context.hook.error
41-
elif hook_name.lower() == "finally_after" or hook_name.lower() == "finally after":
41+
elif hook_name.lower() == 'finally':
4242
return context.hook.finally_after
4343
else:
44-
raise ValueError(str(hook_name) + " is not a valid hook name")
44+
raise ValueError(str(hook_name) + ' is not a valid hook name')
4545

4646

4747
def convert_value_from_flag_type(value, flag_type):
48-
if value == "None":
48+
if value == 'None':
4949
return None
5050
if flag_type.lower() == 'boolean':
5151
return bool(value)
@@ -56,7 +56,7 @@ def convert_value_from_flag_type(value, flag_type):
5656
return value
5757

5858
@then('"{hook_names}" hooks should have evaluation details')
59-
def step_impl(context, hook_names):
59+
def step_impl_should_have_eval_details(context, hook_names):
6060
for hook_name in hook_names.split(', '):
6161
hook = get_hook_from_name(context, hook_name)
6262
for row in context.table:

tests/hook/test_hook_support.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,18 @@ def test_after_hooks_run_after_method(mock_hook):
136136

137137
def test_finally_after_hooks_run_finally_after_method(mock_hook):
138138
# Given
139-
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
139+
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, '')
140140
flag_evaluation_details = FlagEvaluationDetails(
141141
hook_context.flag_key, "val", "unknown"
142142
)
143143
hook_hints = MappingProxyType({})
144144
# When
145-
after_all_hooks(FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], hook_hints)
145+
after_all_hooks(
146+
FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], hook_hints
147+
)
146148
# Then
147149
mock_hook.supports_flag_value_type.assert_called_once()
148150
mock_hook.finally_after.assert_called_once()
149151
mock_hook.finally_after.assert_called_with(
150-
hook_context=hook_context,
151-
details=flag_evaluation_details,
152-
hints=hook_hints
152+
hook_context=hook_context, details=flag_evaluation_details, hints=hook_hints
153153
)

0 commit comments

Comments
 (0)