Projects
Eulaceura:Factory
cloud-init
_service:obs_scm:backport-test-fix-mocking-leak...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:backport-test-fix-mocking-leaks-4815.patch of Package cloud-init
From ef2e48e9344e4849c10475fa9a823d50fb241512 Mon Sep 17 00:00:00 2001 From: Alberto Contreras <alberto.contreras@canonical.com> Date: Mon, 29 Jan 2024 18:30:56 +0100 Subject: [PATCH] test: fix mocking leaks (#4815) In pytest==8.0.0, the collection algorithm changed which results in unittests being executed in a different order. This is shows some mocking leaks that are fixed in this commit, as: - super().tearDown not called - super().setUp doubly called - Distro.default_updates_event not mocked --- tests/unittests/config/test_cc_growpart.py | 1 + tests/unittests/config/test_cc_seed_random.py | 1 + tests/unittests/sources/test_altcloud.py | 4 ++++ tests/unittests/sources/test_azure.py | 1 - tests/unittests/test_stages.py | 4 ++++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unittests/config/test_cc_growpart.py b/tests/unittests/config/test_cc_growpart.py index 85a4759..79c46e2 100644 --- a/tests/unittests/config/test_cc_growpart.py +++ b/tests/unittests/config/test_cc_growpart.py @@ -135,6 +135,7 @@ class TestConfig(TestCase): def tearDown(self): self.tmpfile.close() os.remove(self.tmppath) + super().tearDown() @mock.patch.object(os.path, "isfile", return_value=False) @mock.patch.dict("os.environ", clear=True) diff --git a/tests/unittests/config/test_cc_seed_random.py b/tests/unittests/config/test_cc_seed_random.py index 3ba2a96..b9b1250 100644 --- a/tests/unittests/config/test_cc_seed_random.py +++ b/tests/unittests/config/test_cc_seed_random.py @@ -42,6 +42,7 @@ class TestRandomSeed(TestCase): def tearDown(self): apply_patches([i for i in reversed(self.unapply)]) util.del_file(self._seed_file) + super().tearDown() def apply_patches(self, patches): ret = apply_patches(patches) diff --git a/tests/unittests/sources/test_altcloud.py b/tests/unittests/sources/test_altcloud.py index b4bc44b..dba0f6a 100644 --- a/tests/unittests/sources/test_altcloud.py +++ b/tests/unittests/sources/test_altcloud.py @@ -92,6 +92,7 @@ class TestGetCloudType(CiTestCase): # Reset dmi.read_dmi_data = self.dmi_data force_arch() + super().tearDown() def test_cloud_info_file_ioerror(self): """Return UNKNOWN when /etc/sysconfig/cloud-info exists but errors.""" @@ -230,6 +231,7 @@ class TestGetDataNoCloudInfoFile(CiTestCase): dmi.read_dmi_data = self.dmi_data # Return back to original arch force_arch() + super().tearDown() def test_rhev_no_cloud_file(self): """Test No cloud info file module get_data() forcing RHEV.""" @@ -346,6 +348,7 @@ class TestUserDataVsphere(CiTestCase): pass dsac.CLOUD_INFO_FILE = "/etc/sysconfig/cloud-info" + super().tearDown() @mock.patch("cloudinit.sources.DataSourceAltCloud.util.find_devs_with") @mock.patch("cloudinit.sources.DataSourceAltCloud.util.mount_cb") @@ -409,6 +412,7 @@ class TestReadUserDataCallback(CiTestCase): shutil.rmtree(self.mount_dir) except OSError: pass + super().tearDown() def test_callback_both(self): """Test read_user_data_callback() with both files.""" diff --git a/tests/unittests/sources/test_azure.py b/tests/unittests/sources/test_azure.py index 3a36418..c4be540 100644 --- a/tests/unittests/sources/test_azure.py +++ b/tests/unittests/sources/test_azure.py @@ -1064,7 +1064,6 @@ class TestAzureDataSource(CiTestCase): mock.MagicMock(), ) ) - super(TestAzureDataSource, self).setUp() def apply_patches(self, patches): for module, name, new in patches: diff --git a/tests/unittests/test_stages.py b/tests/unittests/test_stages.py index 7730608..4c54257 100644 --- a/tests/unittests/test_stages.py +++ b/tests/unittests/test_stages.py @@ -441,6 +441,10 @@ class TestInit: assert not self.tmpdir.join(path).exists() @mock.patch("cloudinit.distros.ubuntu.Distro") + @mock.patch.dict( + sources.DataSource.default_update_events, + {EventScope.NETWORK: {EventType.BOOT_NEW_INSTANCE}}, + ) def test_apply_network_on_same_instance_id(self, m_ubuntu, caplog): """Only call distro.networking.apply_network_config_names on same instance id.""" -- 2.27.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2