pulp_smash.selectors¶
Location: Pulp Smash → API Documentation → pulp_smash.selectors
Tools for selecting and deselecting tests.
-
pulp_smash.selectors.
bug_is_fixed
(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, orFalse
otherwise.Raises: TypeError
ifbug_id
is not an integer.Raises: pulp_smash.exceptions.BugStatusUnknownError – If the bug has a status Pulp Smash does not recognize.
-
pulp_smash.selectors.
require
(ver, exc)¶ Optionally skip a test method, based on a version string.
This decorator concisely encapsulates a common pattern for skipping tests. An attribute named
cfg
must be accessible from the decorator. It can be used like so:>>> import unittest >>> from packaging.version import Version >>> from pulp_smash import config, selectors >>> class MyTestCase(unittest.TestCase): ... ... @classmethod ... def setUpClass(cls): ... cls.cfg = config.get_config() ... ... @selectors.require('2.7', unittest.SkipTest) ... def test_foo(self): ... self.assertGreaterEqual(self.cfg.pulp_version, Version('2.7'))
If the same exception should be pased each time this method is called, consider using functools.partial:
>>> from functools import partial >>> from unittest import SkipTest >>> from pulp_smash.selectors import require >>> unittest_require = partial(require, exc=SkipTest)
Parameters: - ver – A PEP 440 compatible version string.
- exc – A class to instantiate and raise as an exception. Its constructor must accept one string argument.
-
pulp_smash.selectors.
skip_if
(func, var_name, result, exc)¶ Optionally skip a test method, based on a condition.
This decorator checks to see if
func(getattr(self, var_name))
equalsresult
. If so, an exception of typeexc
is raised. Otherwise, nothing happens, and the decorated test method continues as normal. Here’s an example of how to use this method:>>> 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, unittest.SkipTest) ... def test_01_skips(self): ... pass ... ... def test_02_runs(self): ... type(self).my_var = True ... ... @skip_if(bool, 'my_var', False, unittest.SkipTest) ... def test_03_runs(self): ... pass
If the same exception should be passed each time this method is called, consider using functools.partial:
>>> from functools import partial >>> from unittest import SkipTest >>> from pulp_smash.selectors import skip_if >>> unittest_skip_if = partial(skip_if, exc=SkipTest)
Parameters: - var_name – A valid variable name.
- result – A value to compare to
func(getattr(self, var_name))
. - exc – A class to instantiate and raise as an exception. Its constructor must accept one string argument.