Skip to content

Commit

Permalink
Fix typo and combine filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Jan 8, 2025
1 parent b8d7403 commit c5ae60b
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions tests/sentry/logging/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,22 @@ def test_gke_emit() -> None:


@mock.patch("random.random", lambda: 0.1)
def test_sampling_filter_pass(caplog, debug_level):
def test_sampling_filter(caplog, set_level_debug):
logger = logging.getLogger(__name__)
with filter_context(logger, [SamplingFilter(0.2)]):
logger.info("msg1")
logger.info("message.2")

captured_msgs = list(map(lambda r: r.msg, caplog.records))
assert sorted(captured_msgs) == ["message.2", "msg1"]


@mock.patch("random.random", lambda: 0.1)
def test_sampling_filter_filter(caplog, debug_level):
logger = logging.getLogger(__name__)
with filter_context(logger, [SamplingFilter(0.05)]):
logger.info("msg1")
logger.info("message.2")

captured_msgs = list(map(lambda r: r.msg, caplog.records))
assert captured_msgs == []
assert sorted(captured_msgs) == ["message.2", "msg1"]


@mock.patch("random.random", lambda: 0.1)
def test_sampling_filter_level(caplog, debug_level):
def test_sampling_filter_level(caplog, set_level_debug):
logger = logging.getLogger(__name__)
with filter_context(logger, [SamplingFilter(0.05, level=logging.WARNING)]):
logger.debug("debug")
Expand All @@ -207,7 +200,7 @@ def test_sampling_filter_level(caplog, debug_level):


@mock.patch("random.random", lambda: 0.1)
def test_sampling_filter_level_default(caplog, debug_level):
def test_sampling_filter_level_default(caplog, set_level_debug):
logger = logging.getLogger(__name__)
with filter_context(logger, [SamplingFilter(0.05)]):
logger.debug("debug")
Expand Down

0 comments on commit c5ae60b

Please sign in to comment.