Skip to content

Resource Groups

mplorentz edited this page May 7, 2015 · 1 revision

The SharedResource class is a mechanism used to document the dependencies for a given test in your test code. By creating a new Resource and decorating the classes or functions that require it with its decorator you are declaring both to the test runner and to other programmers what the test's otherwise implicit dependencies are. In particular, this allows the test runner to run tests in multiple threads without running two tests that depend on the same resource at the same time. For example, we might have a class that tests the permissions of different users. We could also have a class that tests the creation of some object. Both classes make use of the "administrator" user, and the "administrator" cannot be logged in in more than one session. Using ResourceGroups we would declare this dependency in the code like so:

from egautotest.shared_resource import SharedResource
from egautotest.testset import UnorderedTestSet
from egautotest.testset import SequentialTestSet
# First we create our AdminUserResource, a subclass of SharedResource.
class AdminUserResource(SharedResource):

# This class tests the permissions for a certain web application.
class PermissionsTests(UnorderedTestSet):
    def testManagerCanCreateUsers(self):
    def testManagerCannotDeleteUsers(self):
    # This method uses the Administrator User, who cannot be logged in in more than
    # one session. It is decorated with the AdminUserResource decorator to signify
    # this.
    def testAdminCanCreateUsers(self):
    # This method also uses the Administrator User. Since it is also decorated with
    # the AdminUserResource, the TestRunner knows not to run this method at the same
    # time as any other tests with the AdminUserResource.
    def testAdminCanDeleteUsers(self):

# This class tests the process of creating an object Foo.
class TestFooCreation(SequentialTestSet):
    def testOpenFooPage(self):
    def testClickCreateFooButton(self):
    def testFooWasCreated(self):
    # The testFooAuditLog test uses the Administrator username again, so it is
    # decorated with the AdminUserResource decorator. It will not run at the same
    # time as the other methods with the AdminUserResource decorator.
    def testFooAuditLog(self):

If we ask the test runner to run these files in multiple threads, it now knows not to run any of the methods with the AdminUserResource decorator at the same time. ResourceGroup decorators are applied to functions in this example, but the decorators can also be applied to whole classes. Applying a ResourceGroup decorator to a class is the same thing as decorating every function in that class. ResourceGroups work across classes and modules.

You can’t perform that action at this time.