Skip to content

Commit

Permalink
add no_warn option for behavior flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Aug 23, 2024
1 parent 8aff7bf commit 2d7655a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dbt_common/behavior_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def setting(self) -> bool:
def setting(self, value: bool) -> None:
self._setting = value

@property
def no_warn(self) -> bool:
return self._setting

def __bool__(self) -> bool:
return self.setting

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_behavior_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,22 @@ def test_behavior_flags_emit_correct_deprecation(event_catcher) -> None:
assert msg.info.name == "BehaviorDeprecationEvent"
assert msg.data.flag_name == "flag_false"
assert msg.data.flag_source == __name__ # defaults to the calling module


def test_behavior_flags_no_deprecation_event_on_no_warn(event_catcher) -> None:
behavior = register(
behavior_flags=[
{"name": "flag_false", "default": False},
],
user_flags={},
)

# trigger the evaluation with no_warn, no event should fire
if behavior.flag_false.no_warn:
pass
assert len(event_catcher.caught_events) == 0

# trigger the evaluation, an event should fire
if behavior.flag_false:
pass
assert len(event_catcher.caught_events) == 1

0 comments on commit 2d7655a

Please sign in to comment.