pulp_smash.selectors

Location: Pulp SmashAPI Documentationpulp_smash.selectors

Tools for selecting and deselecting tests.

pulp_smash.selectors.bug_is_testable(bug_id, pulp_version)

Tell the caller whether bug bug_id should be tested.

Parameters:
  • bug_id – An integer bug ID, taken from https://pulp.plan.io.
  • pulp_version – A packaging.version.Version object telling the version of the Pulp server we are testing.
Returns:

True if the bug is testable, or False otherwise.

Raises:

TypeError if bug_id is not an integer.

Raises:

pulp_smash.exceptions.BugStatusUnknownError – If the bug has a status Pulp Smash does not recognize.

pulp_smash.selectors.bug_is_untestable(bug_id, pulp_version)

Return the inverse of bug_is_testable().

pulp_smash.selectors.require(version_string)

Optionally skip a test method, based on a version string.

This decorator concisely encapsulates a common pattern for skipping tests. It can be used like so:

>>> from pulp_smash.config import get_config
>>> from pulp_smash.utils import require
>>> from unittest import TestCase
>>> class MyTestCase(TestCase):
...
...     @classmethod
...     def setUpClass(cls):
...         cls.cfg = get_config()
...
...     @require('2.7')  # References `self.cfg`
...     def test_foo(self):
...         pass  # Add a test for Pulp 2.7+ here.

Notice that cls.cfg is assigned to. This is a requirement.

Parameters:version_string – A PEP 440 compatible version string.
pulp_smash.selectors.skip_if(func, var_name, result)

Optionally skip a test method, based on a condition.

This decorator checks to see if func(getattr(self, var_name)) equals result. If so, a unittest.SkipTest exception is raised. Otherwise, nothing happens, and the decorated test method continues as normal. Here’s an example:

>>> import unittest
>>> from pulp_smash.selectors import skip_if
>>> class MyTestCase(unittest.TestCase):
...
...     @classmethod
...     def setUpClass(cls):
...         cls.my_var = False
...
...     @skip_if(bool, 'my_var', False)
...     def test_01_skips(self):
...         pass
...
...     def test_02_runs(self):
...         type(self).my_var = True
...
...     @skip_if(bool, 'my_var', False)
...     def test_03_runs(self):
...         pass
Parameters:var_name – A valid variable name.