Ejemplo n.º 1
0
 def test_queue_listener_sanity(self, tmp_path):
     """
     Given:
         - a ParallelLoggingManager
     When:
         - writing logs to the log file
     Then:
         - assert logs are not written to the file until execute_logs method is called
         - assert all logs appear in file after execute_logs method is called
     """
     pytest.skip(
         "For unknown reason this test cannot pass in the current infra")
     log_file_path = f'{tmp_path}/log_file.log'
     logging_manager = ParallelLoggingManager(log_file_path)
     logging_manager.debug('debug1')
     logging_manager.info('info1')
     logging_manager.warning('warning1')
     logging_manager.error('error1')
     logging_manager.critical('critical1')
     logging_manager.success('success1')
     # Generating exception
     try:
         _ = 1 / 0
     except Exception:
         logging_manager.exception('exception1')
     log_file_lines = self.get_log_content(log_file_path)
     assert not log_file_lines
     logging_manager.execute_logs()
     log_file_lines = self.get_log_content(log_file_path)
     for expected_in_log, log_line in zip(
             self.get_expected_content('1').values(), log_file_lines):
         thread_name, level, content = expected_in_log
         self.assert_log_line(log_line, thread_name, level, content)
Ejemplo n.º 2
0
 def test_real_time_logger_sanity(self, tmp_path):
     """
     Given:
         - a ParallelLoggingManager
     When:
         - writing logs to the log file using the flag 'real_time=True'
     Then:
         - assert logs are written to the file immediately
     """
     pytest.skip(
         "For unknown reason this test cannot pass in the current infra")
     log_file_path = f'{tmp_path}/log_file.log'
     logging_manager = ParallelLoggingManager(log_file_path)
     expected_logs = self.get_expected_content('1')
     logging_manager.debug('debug1', real_time=True)
     self.assert_latest_log_line(log_file_path, *expected_logs['debug'])
     logging_manager.info('info1', real_time=True)
     self.assert_latest_log_line(log_file_path, *expected_logs['info'])
     logging_manager.warning('warning1', real_time=True)
     self.assert_latest_log_line(log_file_path, *expected_logs['warning'])
     logging_manager.error('error1', real_time=True)
     self.assert_latest_log_line(log_file_path, *expected_logs['error'])
     logging_manager.critical('critical1', real_time=True)
     self.assert_latest_log_line(log_file_path, *expected_logs['critical'])
     logging_manager.success('success1', real_time=True)
     self.assert_latest_log_line(log_file_path, *expected_logs['success'])