Decorators Usage Guide

The decorators module

attr(**kwargs)[source]

A decorator which applies the testtools attr decorator

This decorator applies the testtools.testcase.attr if it is in the list of attributes to testtools we want to apply.

Parameters:

condition – Optional condition which if true will apply the attr. If a condition is specified which is false the attr will not be applied to the test function. If not specified, the attr is always applied.

class cleanup_order(func)[source]

Descriptor for base create function to cleanup based on caller.

There are functions created as classmethod and the cleanup was managed by the class with addClassResourceCleanup, In case the function called from a class level (resource_setup) its ok But when it is called from testcase level there is no reason to delete the resource when class tears down.

The testcase results will not reflect the resources cleanup because test may pass but the class cleanup fails. if the resources were created by testcase its better to let the testcase delete them and report failure part of the testcase

idempotent_id(id)[source]

Stub for metadata decorator

related_bug(bug, status_code=None, bug_type='launchpad')[source]

A decorator useful to know solutions from launchpad/storyboard reports

Parameters:
  • bug – The launchpad/storyboard bug number causing the test bug

  • bug_type – ‘launchpad’ or ‘storyboard’, default ‘launchpad’

  • status_code – The status code related to the bug report

serial(cls)[source]

A decorator to mark a test class for serial execution

skip_because(*args, **kwargs)[source]

A decorator useful to skip tests hitting known bugs

bug must be a number and condition must be true for the test to skip.

Parameters:
  • bug – bug number causing the test to skip (launchpad or storyboard)

  • bug_type – ‘launchpad’ or ‘storyboard’, default ‘launchpad’

  • condition – optional condition to be True for the skip to have place

Raises:

testtools.TestCase.skipException if condition is True and bug is included

unstable_test(*args, **kwargs)[source]

A decorator useful to run tests hitting known bugs and skip it if fails

This decorator can be used in cases like:

  • We have skipped tests with some bug and now bug is claimed to be fixed. Now we want to check the test stability so we use this decorator. The number of skipped cases with that bug can be counted to mark test stable again.

  • There is test which is failing often, but not always. If there is known bug related to it, and someone is working on fix, this decorator can be used instead of “skip_because”. That will ensure that test is still run so new debug data can be collected from jobs’ logs but it will not make life of other developers harder by forcing them to recheck jobs more often.

bug must be a number for the test to skip.

Parameters:
  • bug – bug number causing the test to skip (launchpad or storyboard)

  • bug_type – ‘launchpad’ or ‘storyboard’, default ‘launchpad’

Raises:

testtools.TestCase.skipException if test actually fails, and bug is included