On 07/04/2013 11:41 AM, Lucas Meneghel Rodrigues wrote:
> So, instead of doing:
> 
> import platinumlib
> ...
> platinumlib.destroy_all()
> 
> You will do:
> 
> PLATINUMLIB_ENABLED = True
> try:
>     import platinumlib
> except ImportError:
>     PLATINUMLIB_ENABLED = False
> ...
> if not PLATINUMLIB_ENABLED:
>     raise error.TestNAError('Platinum lib is not installed. '
>                             'You need to install the package '
>                             'python-platinumlib for this test '
>                             'to work.')
> platinumlib.destroy_all()
> 
> Any patch that carelessly sticks external library imports in central
> libraries of virt-test for optional features will be downright rejected.
> 
> Thanks for your attention,
> 
> Lucas

Tip: Importing a module modifies the namespace, which is accessible for
code to test directly.  So, unless you want to hide the underlying
library for some reason, this works as well:

try:
     import platinumlib
except ImportError:
     logging.warning('platinumlib is not available')

...

if not globals().has_key('platinumlib'):
     raise ...Error


--And it works from outside that module also--


import goldenplatinum

if not hasattr(goldenplatinum, 'platinumlib'):
    raise ...Error

-- 
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214

_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to