unit testing and maya

Overview
Adding test driven development to your development process can make your code more robust and makes upgrading to new versions of maya much easier. For a good introduction to the concepts take a look at Test Driven Development in python.

This post covers assumes that you are already familiar with the concepts behind test driven development and focuses on how you can use the Nose testing framework to incorporate tdd into maya.

A few assumptions:

  1. You have already installed nose somewhere on your system
  2. Your path environment variables have already been setup so that maya can find the nose module
  3. Your path environment variables have already been setup so that maya can find your script modules

For the purposes of this example lets say that all your scripts are stored under a directory called lot_tools. lot_tools is a standard python package with two sub modules: example_a and example_b.  On disk, that would look like this:

          • lot_tools
                • __init__.py
                • example_a
                  • __init__.py
                  • example_a.py
                  • tests
                    • __init__.ppy
                    • example_a_tests.py
                • example_b

All of the actual work of unit testing is done in the example_a_tests.py. You can have as many test files as you like because nose is very flexible in the discovery of test files. Typically, I will develop a unique test file per file in my module.

”What
Running unittests inside of an interactive maya session
To run your test in maya is as simple as:

If your module fails the tests and you need to make changes, simply make your changes, reload the module and re-run the tests.

If you need to change your tests you will need to restart Maya after you update the test files. This is because the tests are also python modules and I have not figured out the correct module path to reload them. This is normally fine for development purposes because you will normally write your tests first, then write the code to pass the tests.

If you want to run tests on more then one module, you can use nose to both load the modules and the tests at the same time.

Running tests on multiple modules at once

LevelsOfThinking

Leave a Reply

Your email address will not be published. Required fields are marked *