# Decorators Usage Guide

## The decorators module

`attr`(**kwargs)

  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.

`idempotent_id`(id)

  Stub for metadata decorator

`related_bug`(bug, status_code=None, bug_type='launchpad')

  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

`skip_because`(*args, **kwargs)

  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)

  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

this page last updated: 2020-03-30 08:59:08

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug questions?