问题
I am writing unit tests for a script that sends python code to Autodesk Maya trough the commandPort. The script works; it sends code fine to Maya which executes it. For testing purposes however, I want to write a unit test that in its setUp() opens a standalone (commandline) Maya with a commandPort which I can send commands to and then close again in tearDown(), so that I don't have to keep the real Maya application open whenever I work on the scripts.
How do I go about doing that?
回答1:
You can't run commandPort in a standalone, it relies on the GUI loop. You can, however, run a script which makes the standalone listen on a socket, or us a remoting package like zeromq or RPyC. This link includes some hints on how to set it up and points at a github gist with a simple html based RPC server that runs in a standalone.
Alternatively, you can just fire up a complete GUI Maya to control using commandport, although that will slow your tests down considerably.
回答2:
if you're on Linux or Mac, I highly recommend dcc automation project (won't work on Windows). Mainly I liked how rather seamlessly it integrates into Maya.
My setup for unit testing is just launching whole GUI maya, though. I tried the standalone setup and it was just not worth it. C++ unit test suite still run with standalone Maya though, but startup time is just impeding. It's much faster to leave Maya GUI in the background, and test suite connects to it each time a test needs to be launched. Much faster feedback.
I wrote a more in-depth article on my automated test setup for Maya, if you're interested - Automated testing and Maya plugin development.
来源:https://stackoverflow.com/questions/28264406/opening-a-commandport-in-standalone-maya-for-unit-testing