From e6776306b7d486ebd35c8f388b0ff6db51b0752b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 23 Jun 2016 13:42:01 +0200 Subject: [PATCH] Python 3: fix usage of reload() Replace reload() builtin function with six.moves.reload_module() to make the code compatible with Python 2 and Python 3. Change-Id: I7572d613fef700b392d412501facc3bd5ee72a66 --- test/unit/common/test_daemon.py | 3 ++- test/unit/common/test_db_replicator.py | 8 +++++--- test/unit/common/test_manager.py | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/test/unit/common/test_daemon.py b/test/unit/common/test_daemon.py index b81e231571..bae3a146ad 100644 --- a/test/unit/common/test_daemon.py +++ b/test/unit/common/test_daemon.py @@ -17,6 +17,7 @@ import os from six import StringIO +from six.moves import reload_module import unittest from getpass import getuser import logging @@ -69,7 +70,7 @@ class TestRunDaemon(unittest.TestCase): utils.capture_stdio = lambda *args: None def tearDown(self): - reload(utils) + reload_module(utils) def test_run(self): d = MyDaemon({}) diff --git a/test/unit/common/test_db_replicator.py b/test/unit/common/test_db_replicator.py index 29d66df99d..5552c7405a 100644 --- a/test/unit/common/test_db_replicator.py +++ b/test/unit/common/test_db_replicator.py @@ -21,12 +21,14 @@ import logging import errno import math import time -from mock import patch, call from shutil import rmtree, copy from tempfile import mkdtemp, NamedTemporaryFile -import mock import json +import mock +from mock import patch, call +from six.moves import reload_module + from swift.container.backend import DATADIR from swift.common import db_replicator from swift.common.utils import (normalize_timestamp, hash_path, @@ -44,7 +46,7 @@ TEST_CONTAINER_NAME = 'c o n' def teardown_module(): "clean up my monkey patching" - reload(db_replicator) + reload_module(db_replicator) @contextmanager diff --git a/test/unit/common/test_manager.py b/test/unit/common/test_manager.py index c973e4afa0..dc8bc58f1b 100644 --- a/test/unit/common/test_manager.py +++ b/test/unit/common/test_manager.py @@ -24,6 +24,8 @@ import errno from collections import defaultdict from time import sleep, time +from six.moves import reload_module + from swift.common import manager from swift.common.exceptions import InvalidPidFileException @@ -283,7 +285,7 @@ class TestManagerModule(unittest.TestCase): class TestServer(unittest.TestCase): def tearDown(self): - reload(manager) + reload_module(manager) def join_swift_dir(self, path): return os.path.join(manager.SWIFT_DIR, path)