1 Star 0 Fork 29

Andy Lau/cloud-init

forked from src-openEuler/cloud-init 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-test-fix-mocking-leaks-4815.patch 4.30 KB
一键复制 编辑 原始数据 按行查看 历史
桐小哥 提交于 2024-11-05 17:06 +08:00 . test: fix mocking leaks
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wilhelmleibniz/cloud-init.git
git@gitee.com:wilhelmleibniz/cloud-init.git
wilhelmleibniz
cloud-init
cloud-init
master

搜索帮助