wxpython unit-testing problem

Hi,
I’m having trouble coordinating the unittests of my wxpython app. I have two test files with essentially the same layout:
# — test mod layout ---- #
class MyApp(wx.App):
def OnInit(self):
self.frame = wx.Frame(None)
return True
class test_RunGUITests(unittest.TestCase):

def setUp(self):
        self.app = MyApp(redirect=False)
        self.frame = AppFrame(None, title='Accounter')

… Run tests…
def tearDown(self):
self.frame.Destroy()
wx.GetApp().ExitMainLoop()
I then have a file used to execute specified test modules:
# — script used to start the tests — #
if name = ‘main
tests = {0: ‘path/to/testmod1’,
1: ‘path/to/testmod2’}

to_run = [0,1]
for each in to_run:
    nose.run(argv=["w", "-s", testmods[each]])

Both modules run with no problems If I execute them individually, (e.g. set to_run = [1]). However if I try to run them one after the other (to_run = [0,1]) one of the tests in the module being run in second place always fails with the excpetion: PyNoAppError: The wx.App object must be created first!

Having experimented for the last couple of hours I’m no closer to understanding what’s going on. My hunch is that I’m not clearing up my app objects correctly, but I can’t rule out the possibility that the problem is something to do with the workings of nose and/or unittest. Does any one have any ideas?

Hi Paul,

···

On 08/10/2013 20:38, Paul wrote:

Hi,

I'm having trouble coordinating the unittests of my wxpython app. I have two test files with essentially the same layout:

Did you look at the tests in Phoenix?

The setup/teardown is done differently, see unittest\wtc.py

Werner

Hi Werner,

Thanks for the tip. I updated my tearDown() to match that used in wtc.py which at least reassured me that I was closing the app correctly. After having done this I was disappointed to find that I was still encountering similar problems. I then had a more thorough look over wtc.py and noticed that pubsub.pub was also given special treatment in unittest tearDowns. My app uses this module in a couple of places so I updated the relevant methods to dispose of them as per wtc.py, and all is now well.

Many thanks!