summaryrefslogtreecommitdiff
path: root/decorators.py
diff options
context:
space:
mode:
authorFabrice Douchant <Fabrice.Douchant@logilab.fr>2008-10-13 12:38:30 +0200
committerFabrice Douchant <Fabrice.Douchant@logilab.fr>2008-10-13 12:38:30 +0200
commitab9434f0b350b8ca9da6c40e17f12f0a7eba2e9e (patch)
tree0fb2906d0b71ac7cf80ff7514af8536b9c1c55da /decorators.py
parentdbc6734cbc23730c7fd3f46f7994d5950d14c1fb (diff)
downloadlogilab-common-ab9434f0b350b8ca9da6c40e17f12f0a7eba2e9e.tar.gz
add @require_module('module') that skip a test if the module can not be imported
Diffstat (limited to 'decorators.py')
-rw-r--r--decorators.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/decorators.py b/decorators.py
index 7ed4554..71cd325 100644
--- a/decorators.py
+++ b/decorators.py
@@ -167,3 +167,18 @@ def require_version(version):
return f
return check_require_version
+def require_module(module):
+ """ Check if the given module is loaded. Skip the test if not.
+ """
+ def check_require_module(f):
+ try:
+ __import__(module)
+ #print module, 'imported'
+ return f
+ except ImportError:
+ #print module, 'can not be imported'
+ def new_f(self, *args, **kwargs):
+ self.skip('%s can not be imported.' % module)
+ new_f.__name__ = f.__name__
+ return new_f
+ return check_require_module