cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #02857
[Merge] ~chad.smith/cloud-init:gce-mock-test-leak into cloud-init:master
Chad Smith has proposed merging ~chad.smith/cloud-init:gce-mock-test-leak into cloud-init:master.
Requested reviews:
cloud-init commiters (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/327325
test_gce: Fix invalid mock of platform_reports_gce to return False
The mock of platform_reports_gce is created with a True return value in tests/unittests/test_datasource/test_gce.py:TestDataSourceGCE.setUp(). But, the final test_get_data_returns_false_if_not_on_gce incorrectly attempts to override the mocked return_value of True to False by setting self.m_platform_gce.return_value = False. But, since the mock is already initialized, the updated False is not honored. Instead we should use the patch decorator on the specific unit test to override the return_value of DataSourceGCE.platform_reports_gce to False.
A False from platform_reports_gce allows DataSourceGCE.get_data to immediately return False instead of trying to contact metadata.google.internal as the related bug references.
LP:#1703935
--
Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:gce-mock-test-leak into cloud-init:master.
diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
index 6fd1341..3e8398b 100644
--- a/tests/unittests/test_datasource/test_gce.py
+++ b/tests/unittests/test_datasource/test_gce.py
@@ -163,8 +163,9 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
self.assertEqual(True, r)
self.assertEqual('bar', self.ds.availability_zone)
- def test_get_data_returns_false_if_not_on_gce(self):
- self.m_platform_reports_gce.return_value = False
+ @mock.patch('cloudinit.sources.DataSourceGCE.platform_reports_gce')
+ def test_get_data_returns_false_if_not_on_gce(self, m_platform_gce):
+ m_platform_gce.return_value = False
self.assertEqual(False, self.ds.get_data())
Follow ups