Tips and tricks

Initialise variables once in the script

Instances of variables that have been created once by executing the script are retained. You can use the function locals() to check whether the variable already exists.

Example 1. Check whether a variable already exists

A configuration is created in the start file. This configuration should only be created once, the first time the script is executed.

if not 'config' in locals():
    print "Create configuration"
    config = ...
else
    print "Configuration already exists"

Simplified object initialisation

Public properties of .NET classes can be set in the constructor by calling the constructor with an additional argument of the property.

Example 2. Simplified object initialisation
Normal object initialisation
milestone = MilestoneTestStep()
milestone.Name = "Milestone 1"
Simplified object initialisation
milestone = MilestoneTestStep(Name = "Milestone 1")

Last modified 07.03.2024