Question

I am trying to close a wxPython frame in the tearDown method of python's unittest framework. This is the code I am currently attempting to use to setUp and tearDown the frame.

class ValidInputTest4(unittest.TestCase):
    def setUp(self):
        total_food_calories = wx.App()
        self.one = FoodCalories(None)
        total_food_calories.MainLoop()

    def tearDown(self):
        self.one.Close()

This code properly displays the application, but it fails to completely close the application as if a user had manually clicked the "X" button in the top right corner.

Was it helpful?

Solution 3

I found the problem. I need to not start the MainLoop on the app. My working code is now this.

class ValidInputTest4(unittest.TestCase):
    def setUp(self):
        self.app = wx.App()
        self.frame = FoodCalories(None)

    def tearDown(self):
        self.frame.Destroy()

This cleanly exits the program and allows me to do unit tests in between.

OTHER TIPS

Can you try out the Destroy() method? Maybe this works.

Close is the correct method to close a frame, but your code will be stuck in an infinite gui event loop when MainLoop is called until all frames are closed which would have to happen by manually clicking "X" as it wont reach your call to Close.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top