[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.
--- 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