[TIP] Multiplatform testing

Manuel de la Pena Saenz manuel.delapena at canonical.com
Tue Jan 4 00:42:06 PST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 04 Jan 2011, at 00:35, Robert Collins wrote:

> There's also a helper in testtools for this:
> 

That is great, but is there a same helper on unittest? we are using that framework and we would like to have as little dependencies as possible.

>    try_import(name, alternative=None)
>        Attempt to import `name`.  If it fails, return `alternative`.
> 
>        When supporting multiple versions of Python or optional dependencies, it
>        is useful to be able to try to import a module.
> 
>        :param name: The name of the object to import, e.g. 'os.path' or
>            'os.path.join'.
>        :param alternative: The value to return if no module can be imported.
>            Defaults to None.
> 
>    try_imports(module_names, alternative=<object object>)
>        Attempt to import modules.
> 
>        Tries to import the first module in `module_names`.  If it can be
>        imported, we return it.  If not, we go on to the second module and try
>        that.  The process continues until we run out of modules to
> try.  If none
>        of the modules can be imported, either raise an exception or return the
>        provided `alternative` value.
> 
>        :param module_names: A sequence of module names to try to import.
>        :param alternative: The value to return if no module can be imported.
>            If unspecified, we raise an ImportError.
>        :raises ImportError: If none of the modules can be imported and no
>            alternative value was specified.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.16 (Darwin)

iEYEARECAAYFAk0i3V4ACgkQnfYzI4moCF8S+QCeLlhiijwsuwJKm/Y+y9Vq1+c1
l88An2Q3mSEkUCUnbwnZcQi5H7WuLOWN
=wQh/
-----END PGP SIGNATURE-----



More information about the testing-in-python mailing list