I found a great website that discusses functional testing of a Python GUI application using IronPython
, but I want to use Tkinter and am having a hard time making the transition between the libraries.
Michael shows this example for IronPython:
class FunctionalTest(TestCase):
def setUp(self):
self.mainForm = None
self._thread = Thread(ThreadStart(self.startMultiDoc))
self._thread.SetApartmentState(ApartmentState.STA)
self._thread.Start()
while self.mainForm is None:
Thread.CurrentThread.Join(100)
def invokeOnGUIThread(self, function):
return self.mainForm.Invoke(CallTarget0(function))
I'm having a hard time translating that into how I would hook into a Tkinter based application that would have the base setup:
from tkinter import *
from tkinter import ttk
root = Tk()
ttk.Button(root, text="Hello World").grid()
root.mainloop()
I'm thinking you would want to run a method on the main root object in the second thread as well but I'm not seeing an equivalent method to the mainForm.Invoke()
. Maybe I'm thinking about it wrong. Maybe functional testing GUI applications in this manner is not so common?