简体   繁体   中英

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

I'd like to start creating unit tests for my Maya scripts. These scripts must be run inside the Maya environment and rely on the maya.cmds module namespace.

How can I run Nose tests from inside a running environment such as Maya?

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

In order for this work you'll need to run nose programmatically. Create a python file called runtests.py and put it next to your test files. In it, include the following code:

import os
os.environ['PYTHONPATH'] = '/path/to/site-packages'

import nose
nose.run()

Since mayapy loads its own pythonpath, it doesn't know about the site-packages directory where nose is. os.environ is used to set this manually inside the script. Optionally you can set this as a system environment variable as well.

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

/path/to/mayapy.exe runtests.py

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

import maya.standalone
maya.standalone.initialize(name='python')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM