def test_logged_if_slow_deprecated(logger, test_handler): with test_handler.applicationbound(): with logged_if_slow('checking...', threshold=_THRESHOLD, func=logbook.error): sleep(2 * _THRESHOLD) assert test_handler.records[0].level == logbook.ERROR assert test_handler.records[0].message == 'checking...' with pytest.raises(TypeError): logged_if_slow('checking...', logger=logger, func=logger.error)
def test_logged_if_slow_logger(): logger = Mock() with logged_if_slow('checking...', threshold=_THRESHOLD, logger=logger): sleep(2 * _THRESHOLD) assert logger.log.call_args == call(logbook.DEBUG, 'checking...')
def test_logged_if_slow_reached(test_handler): with test_handler.applicationbound(): with logged_if_slow('checking...', threshold=_THRESHOLD): sleep(2 * _THRESHOLD) assert len(test_handler.records) == 1 [record] = test_handler.records assert record.message == 'checking...'
def test_logged_if_slow_level(test_handler): with test_handler.applicationbound(): with logged_if_slow('checking...', threshold=_THRESHOLD, level=logbook.WARNING): sleep(2 * _THRESHOLD) assert test_handler.records[0].level == logbook.WARNING
def test_logged_if_slow_did_not_reached(test_handler): with test_handler.applicationbound(): with logged_if_slow('checking...', threshold=_THRESHOLD): sleep(_THRESHOLD / 2) assert len(test_handler.records) == 0