old_contents: import sys
  import unittest
  import logging
  
  from PyQt5.QtGui import *
  from PyQt5.QtCore import *
  from PyQt5.QtWidgets import *
  
  # set up import paths
  import sas.qtgui.path_prepare
  
  # Local
  from sas.qtgui.Utilities.SasviewLogger import QtHandler
  
  if not QApplication.instance():
      app = QApplication(sys.argv)
  
  class SasviewLoggerTest(unittest.TestCase):
      def setUp(self):
          """
          Prepare the logger
          """
          self.logger = logging.getLogger(__name__)
          self.handler = QtHandler()
          self.handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
          self.logger.addHandler(self.handler)
          self.logger.setLevel(logging.DEBUG)
  
          self.outHandlerGui=QTextBrowser()
  
  
      def testQtHandler(self):
          """
          Test redirection of all levels of logging
          """
          # Attach the listener
          self.handler.messageWritten.connect(self.outHandlerGui.insertPlainText)
  
          # Send the signals
          self.logger.debug('debug message')
          self.logger.info('info message')
          self.logger.warning('warning message')
          self.logger.error('error message')
  
          out=self.outHandlerGui.toPlainText()
  
          # Assure everything got logged
          assert 'DEBUG: debug message' in out
          assert 'INFO: info message' in out
          assert 'WARNING: warning message' in out
          assert 'ERROR: error message' in out
  
  if __name__ == "__main__":
      unittest.main()
  
new_contents: import sys
  import logging
  
  import pytest
  
  from PyQt5.QtGui import *
  from PyQt5.QtCore import *
  from PyQt5.QtWidgets import *
  
  # Local
  from sas.qtgui.Utilities.SasviewLogger import QtHandler
  
  
  class SasviewLoggerTest:
  
      @pytest.fixture(autouse=True)
      def logger(self, qapp):
          '''Create/Destroy the logger'''
          l = logging.getLogger(__name__)
          self.handler = QtHandler()
          self.handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
          l.addHandler(self.handler)
          l.setLevel(logging.DEBUG)
  
          self.outHandlerGui=QTextBrowser()
  
          yield l
  
  
      def testQtHandler(self, logger):
          """
          Test redirection of all levels of logging
          """
          # Attach the listener
          self.handler.messageWritten.connect(self.outHandlerGui.insertPlainText)
  
          # Send the signals
          logger.debug('debug message')
          logger.info('info message')
          logger.warning('warning message')
          logger.error('error message')
  
          out=self.outHandlerGui.toPlainText()
  
          # Assure everything got logged
          assert 'DEBUG: debug message' in out
          assert 'INFO: info message' in out
          assert 'WARNING: warning message' in out
          assert 'ERROR: error message' in out
  
subject: Change to pytest fixtures SasviewLoggerTest.py