import sys
import unittest

from PyQt5 import QtGui, QtWidgets

# set up import paths
import sas.qtgui.path_prepare

# Local
from sas.qtgui.Plotting.WindowTitle import WindowTitle

if not QtWidgets.QApplication.instance():
    app = QtWidgets.QApplication(sys.argv)

class WindowTitleTest(unittest.TestCase):
    '''Test the WindowTitle'''
    def setUp(self):
        '''Create the WindowTitle'''
        self.widget = WindowTitle(None, new_title="some title")

    def tearDown(self):
        '''Destroy the GUI'''
        self.widget.close()
        self.widget = None

    def testDefaults(self):
        '''Test the GUI in its default state'''
        self.widget.show()
        assert isinstance(self.widget, QtWidgets.QDialog)
        assert self.widget.windowTitle() == "Modify Window Title"
        
    def testTitle(self):
        '''Modify the title'''
        self.widget.show()
        QtWidgets.qApp.processEvents()
        # make sure we have the pre-set title
        assert self.widget.txtTitle.text() == "some title"
        # Clear the control and set it to something else
        self.widget.txtTitle.clear()
        self.widget.txtTitle.setText("5 elephants")
        QtWidgets.qApp.processEvents()
        # Retrieve value
        new_title = self.widget.title()
        # Check
        assert new_title == "5 elephants"
       
if __name__ == "__main__":
    unittest.main()

import sys

import pytest

from PyQt5 import QtGui, QtWidgets

# Local
from sas.qtgui.Plotting.WindowTitle import WindowTitle


class WindowTitleTest:
    '''Test the WindowTitle'''

    @pytest.fixture(autouse=True)
    def widget(self, qapp):
        '''Create/Destroy the WindowTitle'''
        w = WindowTitle(None, new_title="some title")

        yield w

        w.close()

    def testDefaults(self, widget):
        '''Test the GUI in its default state'''
        widget.show()
        assert isinstance(widget, QtWidgets.QDialog)
        assert widget.windowTitle() == "Modify Window Title"
        
    def testTitle(self, widget):
        '''Modify the title'''
        widget.show()
        QtWidgets.qApp.processEvents()
        # make sure we have the pre-set title
        assert widget.txtTitle.text() == "some title"
        # Clear the control and set it to something else
        widget.txtTitle.clear()
        widget.txtTitle.setText("5 elephants")
        QtWidgets.qApp.processEvents()
        # Retrieve value
        new_title = widget.title()
        # Check
        assert new_title == "5 elephants"

Change to pytest fixtures WindowTitleTest.py