Skip to content

Commit e02267a

Browse files
authored
Improve bootstrap file logging test (home-assistant#146670)
1 parent 36381e6 commit e02267a

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

tests/test_bootstrap.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ async def test_async_enable_logging(
8585
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
8686
) -> None:
8787
"""Test to ensure logging is migrated to the queue handlers."""
88+
config_log_file_pattern = get_test_config_dir("home-assistant.log*")
89+
arg_log_file_pattern = "test.log*"
90+
91+
# Ensure we start with a clean slate
92+
for f in glob.glob(arg_log_file_pattern):
93+
os.remove(f)
94+
for f in glob.glob(config_log_file_pattern):
95+
os.remove(f)
96+
assert len(glob.glob(config_log_file_pattern)) == 0
97+
assert len(glob.glob(arg_log_file_pattern)) == 0
98+
8899
with (
89100
patch("logging.getLogger"),
90101
patch(
@@ -97,20 +108,24 @@ async def test_async_enable_logging(
97108
):
98109
await bootstrap.async_enable_logging(hass)
99110
mock_async_activate_log_queue_handler.assert_called_once()
111+
assert len(glob.glob(config_log_file_pattern)) > 0
112+
100113
mock_async_activate_log_queue_handler.reset_mock()
101114
await bootstrap.async_enable_logging(
102115
hass,
103116
log_rotate_days=5,
104117
log_file="test.log",
105118
)
106119
mock_async_activate_log_queue_handler.assert_called_once()
107-
for f in glob.glob("test.log*"):
108-
os.remove(f)
109-
for f in glob.glob("testing_config/home-assistant.log*"):
110-
os.remove(f)
120+
assert len(glob.glob(arg_log_file_pattern)) > 0
111121

112122
assert "Error rolling over log file" in caplog.text
113123

124+
for f in glob.glob(arg_log_file_pattern):
125+
os.remove(f)
126+
for f in glob.glob(config_log_file_pattern):
127+
os.remove(f)
128+
114129

115130
async def test_load_hassio(hass: HomeAssistant) -> None:
116131
"""Test that we load the hassio integration when using Supervisor."""

0 commit comments

Comments
 (0)