Fix os.path.join() for unittests under python 3.6

Some unittest cases of trove.tests.unittests.guestagent has mocked
os.path.expanduser(), the result of the mocked function is passed to
os.path.join(). This causes these tests failed under Python3.6 by
TypeError, because a str, bytes or os.PathLike object is expected, but a
MagicMock object is passed in instead. Giving a string return value for
the mocked os.path.expanduser() fixes.

Partial-Bug: #1755417

Change-Id: Ieeb7964a65ceb6fab0f20a0c8fefbe38dd25cb10
Signed-off-by: Zhao Chao <zhaochao1984@gmail.com>
This commit is contained in:
Zhao Chao 2018-03-13 19:00:26 +08:00
parent 33b70e2ce8
commit 5ce26ec392
2 changed files with 4 additions and 2 deletions

View File

@ -796,7 +796,8 @@ class MongodbRestoreTests(trove_testtools.TestCase):
def setUp(self, _):
super(MongodbRestoreTests, self).setUp()
self.patch_ope = patch('os.path.expanduser')
self.patch_ope = patch('os.path.expanduser',
return_value='/tmp/mongo')
self.mock_ope = self.patch_ope.start()
self.addCleanup(self.patch_ope.stop)
self.restore_runner = utils.import_class(

View File

@ -34,7 +34,8 @@ class RedisGuestAgentManagerTest(DatastoreManagerTest):
@patch.object(ImportOverrideStrategy, '_initialize_import_directory')
def setUp(self, *args, **kwargs):
super(RedisGuestAgentManagerTest, self).setUp('redis')
self.patch_ope = patch('os.path.expanduser')
self.patch_ope = patch('os.path.expanduser',
return_value='/tmp/redis')
self.mock_ope = self.patch_ope.start()
self.addCleanup(self.patch_ope.stop)
self.replication_strategy = 'RedisSyncReplication'