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_configdrive.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/unittests/test_datasource/test_configdrive.py') diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py index 51097231..be13165c 100644 --- a/tests/unittests/test_datasource/test_configdrive.py +++ b/tests/unittests/test_datasource/test_configdrive.py @@ -486,11 +486,10 @@ class TestConfigDriveDataSource(CiTestCase): None, helpers.Paths({})) with mock.patch(M_PATH + 'find_candidate_devs') as m_find_devs: - with mock.patch(M_PATH + 'util.is_FreeBSD', return_value=False): - with mock.patch(M_PATH + 'util.mount_cb'): - with mock.patch(M_PATH + 'on_first_boot'): - m_find_devs.return_value = ['/dev/anything'] - self.assertEqual(True, cfg_ds.get_data()) + with mock.patch(M_PATH + 'util.mount_cb'): + with mock.patch(M_PATH + 'on_first_boot'): + m_find_devs.return_value = ['/dev/anything'] + self.assertEqual(True, cfg_ds.get_data()) self.assertEqual('config-disk (/dev/anything)', cfg_ds.subplatform) -- cgit v1.2.3