Use unittest.mock on Python 3

The mock module has been added to Python 3.3 as unittest.mock.

The third party mock module doesn't seem to be maintained anymore: the
last commit was in April 2013.

unittest.mock is more recent, has less bugs and is compatible with
Python 3.4. There are bugs on Python 3 in the third party mock module,
examples:

* https://code.google.com/p/mock/issues/detail?id=225
* https://code.google.com/p/mock/issues/detail?id=234

Oslo Messaging hits these issues when running tests on Python 3.4.

Import oslotest to setup six.moves for mock.

Change-Id: Ic160101695cea67eb9bbbfcaddb8d3dac64e6804
This commit is contained in:
Victor Stinner 2015-04-15 10:39:16 +02:00
parent 57cde6b3ab
commit 72c501454e
28 changed files with 32 additions and 29 deletions

View File

@ -13,6 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
# Import oslotest before importing test submodules to setup six.moves for mock
import oslotest
try:
import eventlet
except ImportError:

View File

@ -17,7 +17,6 @@ import random
import threading
import time
import mock
try:
import qpid
except ImportError:
@ -30,6 +29,7 @@ import oslo_messaging
from oslo_messaging._drivers import amqp
from oslo_messaging._drivers import impl_qpid as qpid_driver
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -22,7 +22,6 @@ import uuid
import fixtures
import kombu
import kombu.transport.memory
import mock
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslotest import mockpatch
@ -34,6 +33,7 @@ from oslo_messaging._drivers import amqpdriver
from oslo_messaging._drivers import common as driver_common
from oslo_messaging._drivers import impl_rabbit as rabbit_driver
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -17,7 +17,6 @@ import logging
import socket
import fixtures
import mock
from oslo_utils import importutils
import testtools
@ -29,6 +28,7 @@ except ImportError:
import oslo_messaging
from oslo_messaging._drivers import common as rpc_common
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
# eventlet is not yet py3 compatible, so skip if not installed
eventlet = importutils.try_import('eventlet')

View File

@ -27,7 +27,6 @@ try:
import eventlet
except ImportError:
eventlet = None
import mock
import testscenarios
import testtools
try:
@ -47,6 +46,7 @@ except ImportError:
impl_eventlet = None
from oslo_messaging._executors import impl_thread
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -15,13 +15,13 @@
import itertools
import mock
from oslo_utils import timeutils
import testscenarios
import oslo_messaging
from oslo_messaging.notify import dispatcher as notify_dispatcher
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -16,13 +16,13 @@
import threading
import time
import mock
from oslo_config import cfg
import testscenarios
import oslo_messaging
from oslo_messaging.notify import dispatcher
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -12,12 +12,11 @@
import logging
import mock
import oslo_messaging
from oslo_messaging.notify import log_handler
from oslo_messaging.tests.notify import test_notifier
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
class PublishErrorsHandlerTestCase(test_utils.BaseTestCase):

View File

@ -18,7 +18,6 @@ import logging.config
import os
import sys
import mock
from oslo_utils import timeutils
import testscenarios
import testtools
@ -26,6 +25,7 @@ import testtools
import oslo_messaging
from oslo_messaging.tests.notify import test_notifier
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -15,11 +15,11 @@
import uuid
import mock
import webob
from oslo_messaging.notify import middleware
from oslo_messaging.tests import utils
from six.moves import mock
class FakeApp(object):

View File

@ -19,7 +19,6 @@ import sys
import uuid
import fixtures
import mock
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from stevedore import dispatch
@ -34,6 +33,7 @@ from oslo_messaging.notify import _impl_test
from oslo_messaging.notify import notifier as msg_notifier
from oslo_messaging import serializer as msg_serializer
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -13,12 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
import testscenarios
import oslo_messaging
from oslo_messaging import serializer as msg_serializer
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -15,12 +15,12 @@
import threading
import mock
from oslo_config import cfg
import testscenarios
import oslo_messaging
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -13,11 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_messaging._drivers import common
from oslo_messaging import _utils as utils
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
class VersionIsCompatibleTestCase(test_utils.BaseTestCase):

View File

@ -7,7 +7,6 @@ hacking>=0.10.0,<0.11
discover
fixtures>=0.3.14
mock>=1.0
mox3>=0.7.0
python-subunit>=0.0.18
testrepository>=0.0.18

View File

@ -13,6 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
# Import oslotest before importing test submodules to setup six.moves for mock
import oslotest
try:
import eventlet
except ImportError:

View File

@ -17,7 +17,6 @@ import random
import threading
import time
import mock
try:
import qpid
except ImportError:
@ -30,6 +29,7 @@ from oslo import messaging
from oslo_messaging._drivers import amqp
from oslo_messaging._drivers import impl_qpid as qpid_driver
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -20,7 +20,6 @@ import uuid
import fixtures
import kombu
import mock
from oslotest import mockpatch
import testscenarios
@ -32,6 +31,7 @@ from oslo_messaging._drivers import amqpdriver
from oslo_messaging._drivers import common as driver_common
from oslo_messaging._drivers import impl_rabbit as rabbit_driver
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -17,9 +17,10 @@ import logging
import socket
import fixtures
import mock
import testtools
from six.moves import mock
try:
import zmq
except ImportError:

View File

@ -15,13 +15,13 @@
import itertools
import mock
from oslo_utils import timeutils
import testscenarios
from oslo import messaging
from oslo.messaging.notify import dispatcher as notify_dispatcher
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -16,13 +16,13 @@
import threading
import time
import mock
import testscenarios
from oslo.config import cfg
from oslo import messaging
from oslo.messaging.notify import dispatcher
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -12,12 +12,11 @@
import logging
import mock
from oslo import messaging
from oslo.messaging.notify import log_handler
from oslo_messaging.tests.notify import test_notifier
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
class PublishErrorsHandlerTestCase(test_utils.BaseTestCase):

View File

@ -18,7 +18,6 @@ import logging.config
import os
import sys
import mock
from oslo_utils import timeutils
import testscenarios
import testtools
@ -27,6 +26,7 @@ from oslo import messaging
import oslo_messaging
from oslo_messaging.tests.notify import test_notifier
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -15,11 +15,11 @@
import uuid
import mock
import webob
from oslo.messaging.notify import middleware
from oslo_messaging.tests import utils
from six.moves import mock
class FakeApp(object):

View File

@ -19,7 +19,6 @@ import sys
import uuid
import fixtures
import mock
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from stevedore import dispatch
@ -34,6 +33,7 @@ from oslo_messaging.notify import _impl_log
from oslo_messaging.notify import _impl_messaging
from oslo_messaging.notify import _impl_test
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -13,12 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
import testscenarios
from oslo import messaging
from oslo.messaging import serializer as msg_serializer
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -15,12 +15,12 @@
import threading
import mock
import testscenarios
from oslo.config import cfg
from oslo import messaging
from oslo_messaging.tests import utils as test_utils
from six.moves import mock
load_tests = testscenarios.load_tests_apply_scenarios

View File

@ -14,9 +14,9 @@ import imp
import os
import warnings
import mock
from oslotest import base as test_base
import six
from six.moves import mock
class DeprecationWarningTest(test_base.BaseTestCase):