Using PyTest with Maya

Hi everyone!

I’m keen to hear from those using PyTest with Maya. What are the pros and cons vs unittest and nose?

From what I’ve read, PyTest is superior to unittest and nose. But maybe there are some gotchas when using it with Maya.

1 Like

Actually I use maya and pyTest in pyCharm. It works really well. There are a lot of features of pyTest that are very advantageous, such as parameter lists, the ability to use fixtures, pyTest plug-ins, etc. To much to go into detail here. If you are running under pyCharm (highly recommended) then you just have to set the project python interpreter to Mayapy.exe.

That’s a great question, basically script testing it’s a huge problem (at least for me),
because there is a lot of situation where you need to automate testing in Maya, and how to do it properly if result only can be seen and checked by a human in the viewport?
Currently, I see no other solution, except manual testing, which is always very time-consuming and not efficient.

Sure, I can try to create some sample scenes, and part of the functions can be automated by unit tests, but how to test the rest?
if anyone has some thoughts on this problem, would be very thankful to read

I build tests to verify the code I’ve written works with real world data that we migrate to our testing environment. Now that I’ve integrated pyTest into our software development workflow, I’ll never go back. It really helps to validate code before it’s released to production.

There is also this package Marcus Albertsson made to help with the setup for Maya and pytest: mayatest · PyPI

(I’ve only tested it - I’ve not really switched from unittest module for Maya testing yet). I’m using pytest extensively in all my pure python code - and will be switching over to it for all my Maya code when I have time to refactor all the tests and set up a CLI to help with that.