tests: remove some global patching
replace a questionable reload_module with idiomatic addCleanup Change-Id: I66d4df1e2dba058b7c719a4a932234b3fc10b554 Signed-off-by: Clay Gerrard <clay.gerrard@gmail.com>
This commit is contained in:
@@ -28,7 +28,6 @@ import json
|
||||
|
||||
from unittest import mock
|
||||
from unittest.mock import patch, call
|
||||
from importlib import reload as reload_module
|
||||
|
||||
from swift.common.db_replicator import BrokerAnnotatedLogger
|
||||
from swift.container.backend import DATADIR
|
||||
@@ -48,11 +47,6 @@ TEST_ACCOUNT_NAME = 'a c t'
|
||||
TEST_CONTAINER_NAME = 'c o n'
|
||||
|
||||
|
||||
def teardown_module():
|
||||
"clean up my monkey patching"
|
||||
reload_module(db_replicator)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def lock_parent_directory(filename):
|
||||
yield True
|
||||
@@ -2370,15 +2364,18 @@ class TestReplicatorSync(unittest.TestCase):
|
||||
self.root, self.datadir, self.backend, mount_check=False,
|
||||
logger=debug_logger())
|
||||
FakeReplConnection = attach_fake_replication_rpc(self.rpc)
|
||||
self._orig_ReplConnection = db_replicator.ReplConnection
|
||||
db_replicator.ReplConnection = FakeReplConnection
|
||||
p = mock.patch.object(db_replicator, 'ReplConnection',
|
||||
FakeReplConnection)
|
||||
p.start()
|
||||
# it turns out this works very well, even if a test leaks a global
|
||||
# patch this will restore the original db_replicator.ReplConnection
|
||||
self.addCleanup(p.stop)
|
||||
self._orig_Ring = db_replicator.ring.Ring
|
||||
self._ring = unit.FakeRing()
|
||||
db_replicator.ring.Ring = lambda *args, **kwargs: self._get_ring()
|
||||
self.logger = debug_logger()
|
||||
|
||||
def tearDown(self):
|
||||
db_replicator.ReplConnection = self._orig_ReplConnection
|
||||
db_replicator.ring.Ring = self._orig_Ring
|
||||
rmtree(self.root)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user