Struggling to make unittest PySide and Maya on commandline work


#1

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 therre’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.


#2

Figured out the answer. The issue was that, in the test multiple Maya files were being opened/closed and more than one instance was being created each time. If you just keep track of one instance globally, the system plays nice