tests/_fixtures.py
def logger(monkeypatch, mocked_config):
    """Fixture to inject a simple stream logger so that we can assert that log messages are emitted."""
    logger = logging.getLogger('dirbs')
    old_propagate = logger.propagate
    logger.propagate = False

    # We assert that the logger does not have any handlers by this stage. If so, setup_initial_logging has
    # erroneously been called here or we imported a module which called setup_initial_logging at import time in the
    # tests (this is a problem for dirbs.api)
    #
    # Disabling this for now as it is not clear yet the tests are all passed at the moment
    # TODO: investigate and fix
    # assert not logger.hasHandlers()

    # Call setup_initial_logging()
    dirbs.logging.setup_initial_logging()

    # Call configure_logging
    dirbs.logging.configure_logging(mocked_config.log_config)

    # Add an initial handler for our tests and give it a name so we can find it
    stream = StringIO()
    hdlr = logging.StreamHandler(stream=stream)
    hdlr.name = 'dirbs.test'
    logger.addHandler(hdlr)
    # Ignore calls to setup_initial_logging. This means that CLI progras invoked via CliRunner.invoke
    # will not have output visible on result.output. Instead, use logger_stream_contents from _helpers.py
    # and pass in the logger yielded by this fixture to get the output of a CliRunner invocation
    monkeypatch.setattr(dirbs.logging, 'setup_initial_logging', lambda: None)
    # ignore setup_file_logging calls
    monkeypatch.setattr(dirbs.logging, 'setup_file_logging', lambda log_config, filename_root: None)
    # Ignore calls to configure_logging
    monkeypatch.setattr(dirbs.logging, 'configure_logging', lambda log_config: None)

    # Yield dirbslogger to test
    yield logger

    # Delete all handler and filters
    del logger.handlers[:]
    del logger.filters[:]
    logger.propagate = old_propagate
Fixture to inject a simple stream logger so that we can assert that log messages are emitted.
Fixture to inject a simple stream logger so that we can assert that log messages are emitted.
Fixture to inject a simple stream logger so that we can assert that log messages are emitted .
def logger(monkeypatch, mocked_config):
    logger = logging.getLogger('dirbs')
    old_propagate = logger.propagate
    logger.propagate = False
     Disabling this for now as it is not clear yet the tests are all passed at the moment
     TODO: investigate and fix
     assert not logger.hasHandlers()
     Call setup_initial_logging()
    dirbs.logging.setup_initial_logging()
     Call configure_logging
    dirbs.logging.configure_logging(mocked_config.log_config)
     Add an initial handler for our tests and give it a name so we can find it
    stream = StringIO()
    hdlr = logging.StreamHandler(stream=stream)
    hdlr.name = 'dirbs.test'
    logger.addHandler(hdlr)
     Ignore calls to setup_initial_logging. This means that CLI progras invoked via CliRunner.invoke
     will not have output visible on result.output. Instead, use logger_stream_contents from _helpers.py
     and pass in the logger yielded by this fixture to get the output of a CliRunner invocation
    monkeypatch.setattr(dirbs.logging, 'setup_initial_logging', lambda: None)
     ignore setup_file_logging calls
    monkeypatch.setattr(dirbs.logging, 'setup_file_logging', lambda log_config, filename_root: None)
     Ignore calls to configure_logging
    monkeypatch.setattr(dirbs.logging, 'configure_logging', lambda log_config: None)
     Yield dirbslogger to test
    yield logger
     Delete all handler and filters
    del logger.handlers[:]
    del logger.filters[:]
    logger.propagate = old_propagate
def logger ( monkeypatch , mocked_config ) : logger = logging . getLogger ( 'dirbs' ) old_propagate = logger . propagate logger . propagate = False dirbs . logging . setup_initial_logging ( ) dirbs . logging . configure_logging ( mocked_config . log_config ) stream = StringIO ( ) hdlr = logging . StreamHandler ( stream = stream ) hdlr . name = 'dirbs.test' logger . addHandler ( hdlr ) monkeypatch . setattr ( dirbs . logging , 'setup_initial_logging' , lambda : None ) monkeypatch . setattr ( dirbs . logging , 'setup_file_logging' , lambda log_config , filename_root : None ) monkeypatch . setattr ( dirbs . logging , 'configure_logging' , lambda log_config : None ) yield logger del logger . handlers [ : ] del logger . filters [ : ] logger . propagate = old_propagate
Fixture to inject a simple stream logger so that we can assert that log messages are emitted.
Fixture to inject a simple stream logger so that we can assert that log messages are emitted .
"""Fixture to inject a simple stream logger so that we can assert that log messages are emitted.""" # We assert that the logger does not have any handlers by this stage. If so, setup_initial_logging has # erroneously been called here or we imported a module which called setup_initial_logging at import time in the # tests (this is a problem for dirbs.api) # # Disabling this for now as it is not clear yet the tests are all passed at the moment # TODO: investigate and fix # assert not logger.hasHandlers() # Call setup_initial_logging() # Call configure_logging # Add an initial handler for our tests and give it a name so we can find it # Ignore calls to setup_initial_logging. This means that CLI progras invoked via CliRunner.invoke # will not have output visible on result.output. Instead, use logger_stream_contents from _helpers.py # and pass in the logger yielded by this fixture to get the output of a CliRunner invocation # ignore setup_file_logging calls # Ignore calls to configure_logging # Yield dirbslogger to test # Delete all handler and filters
monkeypatch
mocked_config