Skip to content

Commit c563462

Browse files
authored
Merge pull request #93 from reddit/debug_log_feature_not_found
Log 'feature not found' to debug logger
2 parents 171b5fe + 88a30c4 commit c563462

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

reddit_decider/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import warnings
32

43
from copy import deepcopy
54
from dataclasses import dataclass
@@ -375,7 +374,7 @@ def expose(
375374
try:
376375
feature = self._internal.get_feature(experiment_name)
377376
except FeatureNotFoundException as exc:
378-
warnings.warn(str(exc))
377+
logger.debug(str(exc))
379378
return
380379
except DeciderException as exc:
381380
logger.info(str(exc))
@@ -772,7 +771,7 @@ def _get_decision(
772771
try:
773772
return self._internal.choose(experiment_name, ctx)
774773
except FeatureNotFoundException as exc:
775-
warnings.warn(str(exc))
774+
logger.debug(str(exc))
776775
return None
777776
except DeciderException as exc:
778777
logger.info(str(exc))
@@ -807,7 +806,7 @@ def _get_dynamic_config_value(
807806
try:
808807
value = get_fn(feature_name=feature_name, context=ctx)
809808
except FeatureNotFoundException as exc:
810-
warnings.warn(str(exc))
809+
logger.debug(str(exc))
811810
return default
812811
except ValueTypeMismatchException as exc:
813812
logger.info(str(exc))
@@ -844,7 +843,7 @@ def get_experiment(self, experiment_name: str) -> Optional[ExperimentConfig]:
844843
try:
845844
feature = self._internal.get_feature(experiment_name)
846845
except FeatureNotFoundException as exc:
847-
warnings.warn(str(exc))
846+
logger.debug(str(exc))
848847
return None
849848
except DeciderException as exc:
850849
logger.info(str(exc))

tests/decider_tests.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,12 @@ def test_none_returned_on_get_variant_call_with_experiment_not_found(self):
562562
)
563563

564564
self.assertEqual(self.event_logger.log.call_count, 0)
565-
with warnings.catch_warnings(record=True) as captured:
565+
with self.assertLogs(logger, logging.DEBUG) as captured:
566566
variant = decider.get_variant("anything")
567567

568-
# can't test warning log only shows up only once if `decider.get_variant("anything")`
569-
# is called again due to bug in `catch_warnings` contextmanager
570-
# see https://github.com/python/cpython/issues/73858
571-
assert any('Feature "anything" not found.' in str(x.message) for x in captured)
568+
assert any(
569+
'Feature "anything" not found.' in x.getMessage() for x in captured.records
570+
)
572571
self.assertEqual(variant, None)
573572

574573
# no exposures should be triggered
@@ -613,13 +612,12 @@ def test_none_returned_on_get_variant_without_expose_call_with_experiment_not_fo
613612
)
614613

615614
self.assertEqual(self.event_logger.log.call_count, 0)
616-
with warnings.catch_warnings(record=True) as captured:
615+
with self.assertLogs(logger, logging.DEBUG) as captured:
617616
variant = decider.get_variant_without_expose("anything")
618617

619-
# can't test warning log only shows up only once if `decider.get_variant("anything")`
620-
# is called again due to bug in `catch_warnings` contextmanager
621-
# see https://github.com/python/cpython/issues/73858
622-
assert any('Feature "anything" not found.' in str(x.message) for x in captured)
618+
assert any(
619+
'Feature "anything" not found.' in x.getMessage() for x in captured.records
620+
)
623621
self.assertEqual(variant, None)
624622

625623
# no exposures should be triggered

0 commit comments

Comments
 (0)