From 1b9a2deaa5c366b11542dc69a03d5aaa1d2e6885 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Tue, 16 Jan 2018 13:49:51 +0100 Subject: [PATCH] Fix glance create client unit tests If tests test_create_glance_client_with_protocol_http and test_create_glance_client_with_protocol_https from cinder.tests.unit.image.test_glance.TestGlanceImageServiceClient are run one after the other (regardless of the order) it will result in an error: "AssertionError: Expected 'load_from_options' to be called once. Called 0 times.". The reason is that in cinder/image/glance.py we cache the session in variable _SESSION, so the first test will set it and the second one will reuse it and won't call the load_from_options method. This patch solves this issue by resetting the caching variable in the tests. TrivialFix Change-Id: Ia77d9d1a3aa4b54a08912584164739f851188784 --- cinder/tests/unit/image/test_glance.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cinder/tests/unit/image/test_glance.py b/cinder/tests/unit/image/test_glance.py index ce4d6ed8ba4..143ccffbbeb 100644 --- a/cinder/tests/unit/image/test_glance.py +++ b/cinder/tests/unit/image/test_glance.py @@ -822,6 +822,7 @@ class TestGlanceImageServiceClient(test.TestCase): @mock.patch.object(ks_session.Session, 'load_from_options') def test_create_glance_client_with_protocol_http( self, mock_load, mock_get_auth_plugin): + glance._SESSION = None self.flags(auth_strategy='keystone') self.flags(glance_request_timeout=None) @@ -850,6 +851,7 @@ class TestGlanceImageServiceClient(test.TestCase): @mock.patch.object(ks_session.Session, 'load_from_options') def test_create_glance_client_with_protocol_https( self, mock_load, mock_get_auth_plugin): + glance._SESSION = None self.flags(auth_strategy='keystone') self.flags(glance_request_timeout=60) self.flags(