Skip to content

Commit 67b4fbb

Browse files
committed
Get correct logger and do not mess with global state
1 parent 56206b4 commit 67b4fbb

2 files changed

Lines changed: 14 additions & 28 deletions

File tree

tests/unit/authorization/test_azure_token_manager.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# pylint: disable=protected-access
44

5-
import logging
65
import time
76
from collections.abc import Generator
87
from typing import Any
@@ -13,7 +12,6 @@
1312
from pydantic import SecretStr
1413
from pytest_mock import MockerFixture
1514

16-
from authorization import azure_token_manager
1715
from authorization.azure_token_manager import (
1816
TOKEN_EXPIRATION_LEEWAY,
1917
AzureEntraIDManager,
@@ -138,15 +136,13 @@ def test_refresh_token_failure_logs_error(
138136
return_value=mock_credential_instance,
139137
)
140138

141-
azure_logger = logging.getLogger(azure_token_manager.__name__)
142-
azure_logger.propagate = True
143-
try:
144-
with caplog.at_level("WARNING"):
145-
result = token_manager.refresh_token()
146-
assert result is False
147-
assert "Failed to retrieve Azure access token" in caplog.text
148-
finally:
149-
azure_logger.propagate = False
139+
with caplog.at_level(
140+
"WARNING", logger="lightspeed_stack.authorization.azure_token_manager"
141+
):
142+
result = token_manager.refresh_token()
143+
144+
assert result is False
145+
assert "Failed to retrieve Azure access token" in caplog.text
150146

151147
def test_token_expired_property_dynamic(
152148
self, token_manager: AzureEntraIDManager, mocker: MockerFixture

tests/unit/models/config/test_rlsapi_v1_configuration.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,10 @@ def test_quota_subject_warns_when_no_limiters(caplog: pytest.LogCaptureFixture)
133133
authentication={"module": "noop"},
134134
quota_handlers={},
135135
)
136-
config_logger = logging.getLogger("models.config")
137-
config_logger.propagate = True
138-
try:
139-
with caplog.at_level(logging.WARNING):
140-
Configuration(**config_dict)
136+
with caplog.at_level(logging.WARNING, logger="lightspeed_stack.models.config"):
137+
Configuration(**config_dict)
141138

142-
assert "quota enforcement is not fully configured" in caplog.text
143-
finally:
144-
config_logger.propagate = False
139+
assert "quota enforcement is not fully configured" in caplog.text
145140

146141

147142
def test_quota_subject_warns_when_no_storage_backend(
@@ -163,12 +158,7 @@ def test_quota_subject_warns_when_no_storage_backend(
163158
],
164159
},
165160
)
166-
config_logger = logging.getLogger("models.config")
167-
config_logger.propagate = True
168-
try:
169-
with caplog.at_level(logging.WARNING):
170-
Configuration(**config_dict)
171-
172-
assert "quota enforcement is not fully configured" in caplog.text
173-
finally:
174-
config_logger.propagate = False
161+
with caplog.at_level(logging.WARNING, logger="lightspeed_stack.models.config"):
162+
Configuration(**config_dict)
163+
164+
assert "quota enforcement is not fully configured" in caplog.text

0 commit comments

Comments
 (0)