fix log flush and clean per test

This commit is contained in:
Jesse Bannon 2023-03-07 17:09:49 -08:00
parent ad1ab33442
commit 660171c4fd
3 changed files with 17 additions and 10 deletions

View file

@ -196,9 +196,12 @@ class Logger:
)
with StreamToLogger(logger=logger) as redirect_stream:
with contextlib.redirect_stdout(new_target=redirect_stream):
with contextlib.redirect_stderr(new_target=redirect_stream):
yield
try:
with contextlib.redirect_stdout(new_target=redirect_stream):
with contextlib.redirect_stderr(new_target=redirect_stream):
yield
finally:
redirect_stream.flush()
@classmethod
def log_exit_exception(cls, exception: Exception, log_filepath: Optional[Path] = None):

View file

@ -14,6 +14,17 @@ import pytest
from ytdl_sub.utils.file_handler import FileHandler
from ytdl_sub.utils.logger import Logger
from ytdl_sub.utils.logger import LoggerLevels
@pytest.fixture(autouse=True)
def cleanup_debug_file():
"""
Clean logs after every test
"""
Logger.set_log_level(log_level_name=LoggerLevels.DEBUG.name)
yield
Logger.cleanup()
@pytest.fixture

View file

@ -6,13 +6,6 @@ from ytdl_sub.utils.logger import Logger
from ytdl_sub.utils.logger import LoggerLevels
@pytest.fixture(autouse=True)
def cleanup_debug_file():
Logger.set_log_level(log_level_name=LoggerLevels.DEBUG.name)
yield
Logger.cleanup()
class TestLogger:
@pytest.mark.parametrize(
"log_level",