在 Autodesk Maya 等 Python 环境中使用 Nose 运行单元测试?

发布于 2024-07-14 18:39:36 字数 123 浏览 5 评论 0原文

我想开始为我的 Maya 脚本创建单元测试。 这些脚本必须在 Maya 环境内运行并依赖于 maya.cmds 模块命名空间。

如何从 Maya 等运行环境内部运行 Nose 测试?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初懵 2024-07-21 18:39:36

使用 Maya 安装中包含的 mayapy 可执行文件而不是标准的 python 可执行文件。

为了完成这项工作,您需要以编程方式运行鼻子。 创建一个名为 runtests.py 的 Python 文件并将其放在测试文件旁边。 在其中包含以下代码:

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

import nose
nose.run()

由于 mayapy 加载自己的 pythonpath,因此它不知道nose 所在的 site-packages 目录。 os.environ 用于在脚本内手动设置。 您也可以选择将其设置为系统环境变量。

从命令行使用 mayapy 应用程序运行 runtests.py 脚本:

/path/to/mayapy.exe runtests.py

您可能需要导入 maya.standalone,具体取决于您的测试的用途。

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

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')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文