mirror of
https://github.com/certbot/certbot.git
synced 2026-04-29 10:09:20 -04:00
add custom skipUnless function
This commit is contained in:
parent
d926a3ac0f
commit
3fe5d9c3e0
1 changed files with 36 additions and 0 deletions
|
|
@ -75,6 +75,42 @@ class AlreadyListeningTestNoPsutil(unittest.TestCase):
|
|||
self.assertEqual(mock_getutil.call_count, 2)
|
||||
|
||||
|
||||
def psutil_available():
|
||||
"""Checks if psutil can be imported.
|
||||
|
||||
:rtype: bool
|
||||
:returns: True iff psutil is installed and can be imported
|
||||
|
||||
"""
|
||||
try:
|
||||
import psutil # pylint: disable=unused-variable
|
||||
except ImportError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def skipUnless(condition, reason):
|
||||
"""Skip tests unless a condition holds.
|
||||
|
||||
This implements the basic functionality of unittest.skipUnless
|
||||
which is only available on Python 2.7+.
|
||||
|
||||
:param bool condition: skip the test iff condition is False
|
||||
:param str reason: the reason for skipping the test
|
||||
|
||||
:rtype: function
|
||||
:returns: a decorator that will hide tests unless condition is True
|
||||
|
||||
"""
|
||||
if hasattr(unittest, "skipUnless"):
|
||||
return unittest.skipUnless(condition, reason)
|
||||
elif condition:
|
||||
return lambda x: x
|
||||
else:
|
||||
return lambda x: None
|
||||
|
||||
|
||||
@skipUnless(psutil_available(), "optional dependency psutil is not available")
|
||||
class AlreadyListeningTestPsutil(unittest.TestCase):
|
||||
"""Tests for certbot.plugins.already_listening."""
|
||||
def _call(self, *args, **kwargs):
|
||||
|
|
|
|||
Loading…
Reference in a new issue