Skip to content

Commit 184c8d5

Browse files
committed
Compatibility: unittest.mock vs. only mock
Python3 has unittest.mock while python2 has only mock. At least on the systems tested (with installed unittest).
1 parent cbc2cdc commit 184c8d5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/test_indexer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
import os, unittest, shutil
21+
import os, sys, unittest, shutil
2222

2323
import pytest
2424
from roundup.backends import get_backend, have_backend
@@ -34,6 +34,11 @@
3434
from .test_sqlite import sqliteOpener
3535
from .test_anydbm import anydbmOpener
3636

37+
try:
38+
from unittest import mock
39+
except ImportError:
40+
import mock
41+
3742
try:
3843
import xapian
3944
skip_xapian = lambda func, *args, **kwargs: func
@@ -280,14 +285,12 @@ def test_xapian_autoselect(self):
280285

281286
@skip_whoosh
282287
def test_whoosh_autoselect(self):
283-
import mock, sys
284288
with mock.patch.dict('sys.modules',
285289
{'roundup.backends.indexer_xapian': None}):
286290
indexer = get_indexer(self.db.config, self.db)
287291
self.assertIn('roundup.backends.indexer_whoosh.Indexer', str(indexer))
288292

289293
def test_native_autoselect(self):
290-
import mock, sys
291294
with mock.patch.dict('sys.modules',
292295
{'roundup.backends.indexer_xapian': None,
293296
'roundup.backends.indexer_whoosh': None}):

0 commit comments

Comments
 (0)