Testing our widgets
So far, we've done well with patch, Mock, and the default TestCase, but testing our widgets module is going to present some new challenges. To begin with, our widgets will need a Tk instance to be their root window. We can create this in each case's setUp() method, but this will slow down the tests considerably, and it isn't really necessary; our tests aren't going to modify the root window, so one root window will suffice for each test case. We can take advantage of the setUpClass() method to create a single instance of Tk just once at class instantiation. Secondly, we have a large number of widgets to test, which means we have a large number of test cases requiring the same boilerplate Tk() setup and tear down.
To address ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access