4.4. Writing Resource Classes

Writing resource classes is similar to writing test classes. The requirements are the same except that, instead of a Run function, you must provide two functions named SetUp and CleanUp. The SetUp function must have the same signature as a test classs Run. The CleanUp function is similar, but does not take a context parameter.

The setup function may add additional properties to the context. These properties will be visible only to tests that require this resource. To add a context property, use Python's dictionary assignment syntax.

Below is an example of setup and cleanup functions for a resource which calls create_my_resource and destroy_my_resource to do the work of creating and destroying the resource. The resource is identified by a string handle, which is inserted into the context under the name Resource.handle, where it may be accessed by tests. Context property names should always have the form Class.name so that there is no risk of collision between properties created by different resource classes.