conftest.py (690B)
1 from io import StringIO 2 3 import pytest 4 from mozlog.formatters import ErrorSummaryFormatter, MachFormatter 5 from mozlog.handlers import StreamHandler 6 from mozlog.structuredlog import StructuredLogger 7 8 9 @pytest.fixture 10 def get_logger(): 11 # Ensure a new state instance is created for each test function. 12 StructuredLogger._logger_states = {} 13 formatters = { 14 "mach": MachFormatter, 15 "errorsummary": ErrorSummaryFormatter, 16 } 17 18 def inner(name, **fmt_args): 19 buf = StringIO() 20 fmt = formatters[name](**fmt_args) 21 logger = StructuredLogger("test_logger") 22 logger.add_handler(StreamHandler(buf, fmt)) 23 return logger 24 25 return inner