I’ve made a set of unit tests for some image manipulations, each manipulation takes an input image and should have a single desired output image.
My plan is to have the desired output image saved in a results folder so that when the tests run and generate an output image, I can compare the generated image data with the corresponding image’s data in the results folder.
This is where wx comes in.
In the unit test if there’s a corresponding image in the results folder it will compare it and move on. Initially though my results folder will be empty so if the corresponding image isn’t there I’m popping a single, simple wx frame with the input and output images side by side with some labels explaining what the manipulation was.
The user can then press an OK or FAIL button depending if the output is correct. If they click ok it saves it to the results folder and the user will never need to manually check the output of that test again.
All of this is working fine, however I get an exception when trying to initialise the second frame in the tests (the program will load one frame just fine)
This is a simple version showing the error:
import unittest
import wx
class TestCase(unittest.TestCase):
def test_something(self):
“”“This test tests a series of things and needs the user to validate the result visually”""
for i in xrange(3):
app= wx.App(False)
frame= wx.Frame(None)
frame.Show()
app.MainLoop()
if name == “main”:
unittest.main()
which throws “PyNoAppError: The wx.App object must be created first!” after closing the first frame.
I thought initially that maybe you can’t create an app twice in the same program but from the looks of this, you definitely can.
Why does my version not work? Is there some magic about putting wx.App in the setUp method that makes it work?
Is it possible to make the version above work?
I could refactor the code so that only one frame is shown per test method so I can put wx.App in the setUp method but it would be difficult and a lot of work as I’ve already written everything, only this part isn’t working.
The reason it would be difficult is because the loop in the test method is dynamic, and I’d need to do some rather complicated meta coding to loop over these dynamic loops making test methods for the test class at run time.
Thanks and hope I’ve provided enough info!