[devtools] Make dependency on backports.tempfile (Python2) optional
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 26 Oct 2016 08:34:34 +0200
changeset 11751 b57b76091481
parent 11750 18e7b9829471
child 11752 8c45f52b76e4
[devtools] Make dependency on backports.tempfile (Python2) optional The package may not be available in all systems (e.g. no Debian package exist at the moment), and we should not crash with ImportError when importing testlib from client code. Follow up on a6dc650bc230 where the dependency was introduced.
cubicweb/devtools/testlib.py
--- a/cubicweb/devtools/testlib.py	Wed Sep 28 22:17:36 2016 +0200
+++ b/cubicweb/devtools/testlib.py	Wed Oct 26 08:34:34 2016 +0200
@@ -57,7 +57,11 @@
     from unittest2 import TestCase
     if not hasattr(TestCase, 'subTest'):
         raise ImportError('no subTest support in available unittest2')
-    from backports.tempfile import TemporaryDirectory  # noqa
+    try:
+        from backports.tempfile import TemporaryDirectory  # noqa
+    except ImportError:
+        # backports.tempfile not available
+        TemporaryDirectory = None
 else:
     from unittest import TestCase
     from tempfile import TemporaryDirectory  # noqa