From 31daf6670aeeba1d452c70bc0d4d04139652be36 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Mon, 22 Nov 2021 16:56:41 -0600 Subject: testing: monkeypatch system_info call in unit tests (SC-533) (#1117) testing: monkeypatch system_info call in unit tests system_info can make calls that read or write from the filesystem, which should require special mocking. It is also decorated with 'lru_cache', which means test authors often don't realize they need to be mocking. Also, we don't actually want the results from the user's local machine, so monkeypatching it across all tests should be reasonable. Additionally, moved some of 'system_info` into a helper function to reduce the surface area of the monkeypatch, added tests for the new function (and fixed a bug as a result), and removed related mocks that should be no longer needed. --- tests/unittests/test_datasource/test_azure_helper.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/unittests/test_datasource/test_azure_helper.py') diff --git a/tests/unittests/test_datasource/test_azure_helper.py b/tests/unittests/test_datasource/test_azure_helper.py index 552c7905..ab4f0b50 100644 --- a/tests/unittests/test_datasource/test_azure_helper.py +++ b/tests/unittests/test_datasource/test_azure_helper.py @@ -129,9 +129,7 @@ class TestFindEndpoint(CiTestCase): self.dhcp_options.return_value = {"eth0": {"unknown_245": "5:4:3:2"}} self.assertEqual('5.4.3.2', wa_shim.find_endpoint(None)) - @mock.patch('cloudinit.sources.helpers.azure.util.is_FreeBSD') - def test_latest_lease_used(self, m_is_freebsd): - m_is_freebsd.return_value = False # To avoid hitting load_file + def test_latest_lease_used(self): encoded_addresses = ['5:4:3:2', '4:3:2:1'] file_content = '\n'.join([self._build_lease_content(encoded_address) for encoded_address in encoded_addresses]) -- cgit v1.2.3