Creating a first test function

When starting to write a test function, it’s often necessary to check which arguments or prerequisites create_maya_scene requires. This can take some time. Instead, it’s easier to start writing the test function. Error messages at runtime will show exactly what’s needed. Let’s take a look at create_maya_scene:

def create_maya_scene(parent, name='main', uuid=None, user=None, filetype=None, description='', version=None, current=None, variant='', **kwargs):
    [...]

create_maya_scene needs one positional argument. The other arguments are keyword arguments, and it’s not clear if they are optional. The docstring shows that the parent parameter should be an instance of an Asset or Shot object. Asset and Shot are both ORM models. So let’s go with a Shot because this seems easier. The simplest test function looks like this:

def test_create_maya_scene():
    shot = Shot('myAwesomeShot')
    create_maya_scene(shot)

The execution of the test function fails. It turns out that a User object is required as a keyword argument. So an instance of User is passed to create_maya_scene.

def test_create_maya_scene():
    shot = Shot('myAwesomeShot')
    user = User('Jan Honsbrok', 'janhon')

    create_maya_scene(shot, user=user)

The execution of the test function still fails, because a File is required as the current parameter.

def test_create_maya_scene():
    shot = Shot('myAwesomeShot')
    user = User('Jan Honsbrok', 'janhon')
    current = File(shot=shot)

    create_maya_scene(shot, user=user, current=current)

create_maya_scene can now start to run without complaints about missing parameters.

Last modified August 24, 2020