How do I run unittest on a Tkinter app?

I've just begun learning about TDD, and I'm developing a program using a Tkinter GUI. The only problem is that once the .mainloop() method is called, the test suite hangs until the window is closed.

Here is an example of my code:

# server.py
import Tkinter as tk

class Server(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.mainloop()

# test.py
import unittest
import server

class ServerTestCase(unittest.TestCase):
    def testClassSetup(self):
       server.Server()
       # and of course I can't call any server.whatever functions here

if __name__ == '__main__':
    unittest.main()

What is the appropriate way of testing Tkinter apps? Or is it just 'dont'?

19
задан Stevoisiak supports Monica 15 May 2018 в 15:24
поделиться