mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Prevent log flooding in frame helper (#61085)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Test the frame helper."""
|
||||
# pylint: disable=protected-access
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
@@ -70,3 +71,24 @@ async def test_extract_frame_no_integration(caplog):
|
||||
],
|
||||
), pytest.raises(frame.MissingIntegrationFrame):
|
||||
frame.get_integration_frame()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_integration_frame")
|
||||
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
|
||||
async def test_prevent_flooding(caplog):
|
||||
"""Test to ensure a report is only written once to the log."""
|
||||
|
||||
what = "accessed hi instead of hello"
|
||||
key = "/home/paulus/homeassistant/components/hue/light.py:23"
|
||||
|
||||
frame.report(what, error_if_core=False)
|
||||
assert what in caplog.text
|
||||
assert key in frame._REPORTED_INTEGRATIONS
|
||||
assert len(frame._REPORTED_INTEGRATIONS) == 1
|
||||
|
||||
caplog.clear()
|
||||
|
||||
frame.report(what, error_if_core=False)
|
||||
assert what not in caplog.text
|
||||
assert key in frame._REPORTED_INTEGRATIONS
|
||||
assert len(frame._REPORTED_INTEGRATIONS) == 1
|
||||
|
||||
Reference in New Issue
Block a user