代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/cloud-init 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。