Skip to content

testing: Add missing mock to networking test#1353

Merged
blackboxsw merged 2 commits into
canonical:mainfrom
TheRealFalcon:test-mock2
Mar 29, 2022
Merged

testing: Add missing mock to networking test#1353
blackboxsw merged 2 commits into
canonical:mainfrom
TheRealFalcon:test-mock2

Conversation

@TheRealFalcon
Copy link
Copy Markdown
Contributor

Is failing for me locally (but not in CI)

Comment thread tests/unittests/test_net_freebsd.py Outdated
@mock.patch("cloudinit.net.get_interfaces_by_mac")
@mock.patch("cloudinit.subp.subp")
def test_render_output_has_yaml(self, mock_subp):
def test_render_output_has_yaml(self, m_get_interfaces, m_subp):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this instead be the following diff? If not, minimally the order of the mocked params should switch

diff --git a/tests/unittests/test_net_freebsd.py b/tests/unittests/test_net_freebsd.py
index 3facb2bb4..bf850ceaf 100644
--- a/tests/unittests/test_net_freebsd.py
+++ b/tests/unittests/test_net_freebsd.py
@@ -61,8 +61,10 @@ class TestFreeBSDRoundTrip(CiTestCase):
         return dir2dict(target)
 
     @mock.patch("cloudinit.subp.subp")
-    def test_render_output_has_yaml(self, mock_subp):
+    @mock.patch("cloudinit.util.is_FreeBSD", return_value=True)
+    def test_render_output_has_yaml(self, _is_freebsd, mock_subp):
 
+        mock_subp.return_value = (SAMPLE_FREEBSD_IFCONFIG_OUT, 0)
         entry = {
             "yaml": V1,
         }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is better

@blackboxsw blackboxsw self-assigned this Mar 28, 2022
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@blackboxsw blackboxsw merged commit b1c8c3d into canonical:main Mar 29, 2022
@TheRealFalcon TheRealFalcon deleted the test-mock2 branch March 21, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants