代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/cloud-init 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From dc0eafbc7d88be99e11301081adb41ad7b50338e Mon Sep 17 00:00:00 2001
From: James Falcon <james.falcon@canonical.com>
Date: Mon, 11 Mar 2024 19:37:48 -0500
Subject: [PATCH] test: fix `disable_sysfs_net` mock (#5065)
The fixture parametrization ability added in 9baf31c doesn't work
as expected. When you have a session-wide fixture, the setup is run
once, then further invocations of the fixture (including autouse) uses a
cached version of the fixture. Teardown for the session fixture happens
at the end of all test runs. This also applies to mock patching. Since
the mock patching happens only once, parametrizing the fixture to yield
without patching doesn't undo the initial mock setup; the
parametrization of `disable_sys_net` effectively does nothing.
The good news is that patches stack, so current tests that patch
`get_sys_class_path` differently will still work fine. If we need to
disable the patching entirely, that is also possible by saving the
original `get_sys_class_path` before applying the global disable mock,
then having a separate mock that has a side effect of calling
the original function.
Reference:https://github.com/canonical/cloud-init/commit/dc0eafbc7d88be99e11301081adb41ad7b50338e
Conflict:NA
---
tests/unittests/conftest.py | 14 ++------------
tests/unittests/net/test_init.py | 5 +----
2 files changed, 3 insertions(+), 16 deletions(-)
diff --git a/tests/unittests/conftest.py b/tests/unittests/conftest.py
index 22bc189..bdd21c3 100644
--- a/tests/unittests/conftest.py
+++ b/tests/unittests/conftest.py
@@ -62,18 +62,8 @@ def fake_filesystem(mocker, tmpdir):
@pytest.fixture(scope="session", autouse=True)
-def disable_sysfs_net(request, tmpdir_factory):
- """Avoid tests which read the undertying host's /syc/class/net.
-
- To allow unobscured reads of /sys/class/net on the host we can
- parametrize the fixture with:
-
- @pytest.mark.parametrize("disable_sysfs_net", [False], indirect=True)
- """
- if hasattr(request, "param") and getattr(request, "param") is False:
- # Test disabled this fixture, perform no mocks.
- yield
- return
+def disable_sysfs_net(tmpdir_factory):
+ """Avoid tests which read the underlying host's /syc/class/net."""
mock_sysfs = f"{tmpdir_factory.mktemp('sysfs')}/"
with mock.patch(
"cloudinit.net.get_sys_class_path", return_value=mock_sysfs
diff --git a/tests/unittests/net/test_init.py b/tests/unittests/net/test_init.py
index a7b75ab..51e54d0 100644
--- a/tests/unittests/net/test_init.py
+++ b/tests/unittests/net/test_init.py
@@ -42,10 +42,7 @@ class TestSysDevPath:
class TestReadSysNet:
@pytest.fixture(autouse=True)
- @pytest.mark.parametrize(
- "disable_sysfs_net", [False], indirect=["disable_sysfs_net"]
- )
- def setup(self, disable_sysfs_net, tmpdir_factory):
+ def setup(self, tmpdir_factory):
# We mock invididual numbered tmpdirs here because these tests write
# to the sysfs directory and stale test artifacts break later tests.
mock_sysfs = f"{tmpdir_factory.mktemp('sysfs', numbered=True)}/"
--
2.43.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。