mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
feat: Refactor and expand CLI smoke tests for subcommand/config coverage (#581)
This commit is contained in:
@@ -1358,3 +1358,29 @@ class TestKleinanzeigenBotChangedAds:
|
||||
|
||||
# The changed ad should be loaded with 'due' selector because it's due for republication
|
||||
assert len(ads_to_publish) == 1
|
||||
|
||||
|
||||
def test_file_logger_writes_message(tmp_path:Path, caplog:pytest.LogCaptureFixture) -> None:
|
||||
"""
|
||||
Unit: Logger can be initialized and used, robust to pytest log capture.
|
||||
"""
|
||||
log_path = tmp_path / "logger_test.log"
|
||||
logger_name = "logger_test_logger_unique"
|
||||
logger = logging.getLogger(logger_name)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.propagate = False
|
||||
for h in list(logger.handlers):
|
||||
logger.removeHandler(h)
|
||||
handle = logging.FileHandler(str(log_path), encoding = "utf-8")
|
||||
handle.setLevel(logging.DEBUG)
|
||||
formatter = logging.Formatter("%(levelname)s:%(name)s:%(message)s")
|
||||
handle.setFormatter(formatter)
|
||||
logger.addHandler(handle)
|
||||
logger.info("Logger test log message")
|
||||
handle.flush()
|
||||
handle.close()
|
||||
logger.removeHandler(handle)
|
||||
assert log_path.exists()
|
||||
with open(log_path, "r", encoding = "utf-8") as f:
|
||||
contents = f.read()
|
||||
assert "Logger test log message" in contents
|
||||
|
||||
Reference in New Issue
Block a user