1414import transaction
1515from transaction .interfaces import NoTransaction
1616from zope import interface
17- from nti .testing import zodb
17+ try :
18+ from nti .testing import zodb
19+ base_mock_db_trans = zodb .mock_db_trans
20+ except ModuleNotFoundError as ex :
21+ assert ex .name == 'ZODB'
22+ zodb = None
23+ base_mock_db_trans = object
1824
1925# pylint:disable=protected-access,pointless-string-statement
2026
@@ -41,7 +47,7 @@ def cacheMinimize(self):
4147 self .minimized = True
4248
4349
44- class MockDBTrans (zodb . mock_db_trans ):
50+ class MockDBTrans (base_mock_db_trans ):
4551
4652 def __init__ (self , db = None ):
4753 if db is None :
@@ -52,6 +58,8 @@ def __init__(self, db=None):
5258class TestMockDBTrans (unittest .TestCase ):
5359
5460 def setUp (self ):
61+ if zodb is None :
62+ self .skipTest ("ZODB not installed" )
5563 self ._was_explicit = transaction .manager .explicit
5664 transaction .manager .explicit = False
5765
@@ -226,7 +234,7 @@ def __bool__(self):
226234 class MyMock (MockDBTrans ):
227235 seen_tx = None
228236 aborted = False
229- def on_connection_opened (self , conn ):
237+ def on_connection_opened (self , _conn ):
230238 # pylint:disable=no-member
231239 self .seen_tx = self ._mock_db_trans__current_transaction
232240 abort = self .seen_tx .abort
@@ -255,7 +263,13 @@ def _abort():
255263
256264class TestZODBLayer (unittest .TestCase ):
257265
258- layer = zodb .ZODBLayer
266+ if zodb is not None :
267+ layer = zodb .ZODBLayer
268+
269+ def setUp (self ):
270+ super ().setUp ()
271+ if zodb is None :
272+ self .skipTest ("ZODB not installed" )
259273
260274 def test_registration (self ):
261275 from ZODB .interfaces import IDatabase
@@ -288,10 +302,14 @@ def __init__(self, *args):
288302 pass
289303
290304class TestResetDbCaches (unittest .TestCase ):
291- layer = zodb .ZODBLayer
305+
306+ if zodb is not None :
307+ layer = zodb .ZODBLayer
292308
293309 def setUp (self ):
294310 super ().setUp ()
311+ if zodb is None :
312+ self .skipTest ("ZODB not installed" )
295313 gc .disable ()
296314
297315 def tearDown (self ):
0 commit comments