diff options
author | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-13 12:38:30 +0200 |
---|---|---|
committer | Fabrice Douchant <Fabrice.Douchant@logilab.fr> | 2008-10-13 12:38:30 +0200 |
commit | ab9434f0b350b8ca9da6c40e17f12f0a7eba2e9e (patch) | |
tree | 0fb2906d0b71ac7cf80ff7514af8536b9c1c55da /decorators.py | |
parent | dbc6734cbc23730c7fd3f46f7994d5950d14c1fb (diff) | |
download | logilab-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.py | 15 |
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 |