Reputation: 998
I have a Maya environment with a PySide window which gets generated on the fly with whatever is in that Maya scene. I'm trying to now take that to command-line and make unittests out of it.
I have everything working, minus one problem. Most PyQt/PySide unittest documentation state to create a QApplication like this:
app = QApplication(sys.argv)
win = SomeWindow()
sys.exit(app.exec_())
This doesn't work because there's already a QApplication instance, built from Maya.
RuntimeError: A QApplication instance already exists.
Excluding these steps though yields this error and the tests fail:
QWidget: Cannot create a QWidget when no GUI is being used
I know that there's a QApplication instance in the scene, because this command yields a QApplication instance:
QApplication.instance()
So how do I associate the GUI that I want to create with that instance? You can't exec_() Maya's running QApplication so I'm not sure how to get my GUI to see the QApplication. _
Upvotes: 0
Views: 464
Reputation: 998
Found the solution. The issue was that I wasn't holding a global reference to the same instance across all of my tests (multiple Maya files were being created/destroyed over and over).
So somewhere at the top of the file, you just write
APP = None
Then in each test, import another file that keeps a link to that QApplication instance as a singleton and set APP equal to it
Upvotes: 1