Running unit tests with Nose inside a Python environment like Autodesk Maya?

I would like to start creating unit tests for Maya scripts. These scripts should run inside the Maya environment and rely on the maya.cmds module maya.cmds .

How to run Nose tests from a production environment like Maya?

+6
python unit-testing environment nose maya
source share
1 answer

Use the mayapy executable included in your maya version instead of the standard python executable.

For this to work, you will need to launch your nose programmatically. Create a python file called runtests.py and place it next to your test files. Include the following code in it:

 import os os.environ['PYTHONPATH'] = '/path/to/site-packages' import nose nose.run() 

Since mayapi loads its own pythonpath, it does not know about the directory of package sites where the nose is. os.environ is used to set this manually inside the script. If you wish, you can also set this as a system environment variable.

At the command line, use the mayapy application to run the runtests.py script:

/path/to/mayapy.exe runtests.py

You may need to import maya.standalone depending on what your tests do.

 import maya.standalone maya.standalone.initialize(name='python') 
+15
source share

All Articles