From 2d7655ac6be924c81777f6c556b382544ded65ee Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Fri, 23 Aug 2024 16:40:15 -0400 Subject: [PATCH] add no_warn option for behavior flags --- dbt_common/behavior_flags.py | 4 ++++ tests/unit/test_behavior_flags.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/dbt_common/behavior_flags.py b/dbt_common/behavior_flags.py index 3dc9ce8..3a85022 100644 --- a/dbt_common/behavior_flags.py +++ b/dbt_common/behavior_flags.py @@ -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 diff --git a/tests/unit/test_behavior_flags.py b/tests/unit/test_behavior_flags.py index a40ea52..b719faf 100644 --- a/tests/unit/test_behavior_flags.py +++ b/tests/unit/test_behavior_flags.py @@ -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