#----------------------------------------------------------------------------- # Copyright (c) 2012 - 2021, Anaconda, Inc., and Bokeh Contributors. # All rights reserved. # # The full license is in the file LICENSE.txt, distributed with this software. #----------------------------------------------------------------------------- ''' Define a Pytest plugin for a log file fixture ''' #----------------------------------------------------------------------------- # Boilerplate #----------------------------------------------------------------------------- from __future__ import annotations import logging # isort:skip log = logging.getLogger(__name__) #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- # Standard library imports from typing import IO, Iterator # External imports import pytest #----------------------------------------------------------------------------- # Globals and constants #----------------------------------------------------------------------------- __all__ = ( 'log_file', ) #----------------------------------------------------------------------------- # General API #----------------------------------------------------------------------------- @pytest.fixture(scope="session") def log_file(request: pytest.FixtureRequest) -> Iterator[IO[str]]: with open(request.config.option.log_file, 'w') as f: # Clean-out any existing log-file f.write("") with open(request.config.option.log_file, 'a') as f: yield f #----------------------------------------------------------------------------- # Dev API #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # Private API #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # Code #-----------------------------------------------------------------------------