Mercurial > p > roundup > code
diff test/test_indexer.py @ 7070:c6b2534a58a9
Compatibility: unittest.mock vs. only mock
Python3 has unittest.mock while python2 has only mock. At least on the
systems tested (with installed unittest).
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Thu, 24 Nov 2022 10:29:37 +0100 |
| parents | 9ff091537f43 |
| children | 890b8f4ff38e |
line wrap: on
line diff
--- a/test/test_indexer.py Wed Nov 23 21:16:01 2022 +0100 +++ b/test/test_indexer.py Thu Nov 24 10:29:37 2022 +0100 @@ -18,7 +18,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -import os, unittest, shutil +import os, sys, unittest, shutil import pytest from roundup.backends import get_backend, have_backend @@ -35,6 +35,11 @@ from .test_anydbm import anydbmOpener try: + from unittest import mock +except ImportError: + import mock + +try: import xapian skip_xapian = lambda func, *args, **kwargs: func except ImportError: @@ -280,14 +285,12 @@ @skip_whoosh def test_whoosh_autoselect(self): - import mock, sys with mock.patch.dict('sys.modules', {'roundup.backends.indexer_xapian': None}): indexer = get_indexer(self.db.config, self.db) self.assertIn('roundup.backends.indexer_whoosh.Indexer', str(indexer)) def test_native_autoselect(self): - import mock, sys with mock.patch.dict('sys.modules', {'roundup.backends.indexer_xapian': None, 'roundup.backends.indexer_whoosh': None}):
