Merge ~ogayot/ubiquity:fix-unittest-python3.11 into ubiquity:main

Proposed by Olivier Gayot
Status: Merged
Merged at revision: 0e37f20cccbbc819f22ad2e836cca5cccedecc31
Proposed branch: ~ogayot/ubiquity:fix-unittest-python3.11
Merge into: ubiquity:main
Diff against target: 54 lines (+10/-4)
2 files modified
debian/changelog (+6/-0)
tests/test_ubi_console_setup.py (+4/-4)
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Review via email: mp+436402@code.launchpad.net

Commit message

tests: make test_ubi_console_setup compatible with python 3.11

Description of the change

In python3.11, the pkgutil.resolve_name function is called by unitest.mock.patch. This makes mock.patch unable to cope with invalid python module names (i.e., that contains hyphens).

It is a problem for ubiquity since we import modules that contain hyphens using importlib through load_plugins.

To work around the issue, patch the imported object rather than patching the symbol name.

To post a comment you must log in.
Revision history for this message
Olivier Gayot (ogayot) wrote :
Revision history for this message
Steve Langasek (vorlon) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index e4632df..3f1e355 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,9 @@
6+ubiquity (23.04.3) lunar; urgency=medium
7+
8+ * Fix unittest failing with Python 3.11 (LP: #2003970)
9+
10+ -- Olivier Gayot <olivier.gayot@canonical.com> Thu, 26 Jan 2023 19:36:54 +0100
11+
12 ubiquity (23.04.2) lunar; urgency=medium
13
14 * Fix lunar's pep8, not cought with local rebuild due to noautomatic.
15diff --git a/tests/test_ubi_console_setup.py b/tests/test_ubi_console_setup.py
16index f83bbed..3fe6069 100644
17--- a/tests/test_ubi_console_setup.py
18+++ b/tests/test_ubi_console_setup.py
19@@ -30,7 +30,7 @@ class TestPage(TestPageBase):
20 ("xkb", "gb"),
21 ]
22
23- @unittest.mock.patch("ubi-console-setup.gsettings.set_list")
24+ @unittest.mock.patch.object(ubi_console_setup.gsettings, "set_list")
25 def test_set_gnome_keyboard_layout_with_variant(self, set_list_mock):
26 self.page.gnome_input_sources = self.DEFAULT_ENGLISH_KEYBOARDS
27 self.page.set_gnome_keyboard_layout("de", "neo")
28@@ -49,7 +49,7 @@ class TestPage(TestPageBase):
29 ]
30 )
31
32- @unittest.mock.patch("ubi-console-setup.gsettings.set_list")
33+ @unittest.mock.patch.object(ubi_console_setup.gsettings, "set_list")
34 def test_set_gnome_keyboard_layout_without_variant(self, set_list_mock):
35 self.page.gnome_input_sources = self.DEFAULT_ENGLISH_KEYBOARDS
36 self.page.set_gnome_keyboard_layout("de", "")
37@@ -68,7 +68,7 @@ class TestPage(TestPageBase):
38 ]
39 )
40
41- @unittest.mock.patch("ubi-console-setup.gsettings.set_list")
42+ @unittest.mock.patch.object(ubi_console_setup.gsettings, "set_list")
43 def test_set_gnome_keyboard_layout_to_existing_layout(self, set_list_mock):
44 self.page.gnome_input_sources = self.DEFAULT_ENGLISH_KEYBOARDS
45 self.page.set_gnome_keyboard_layout("gb", "")
46@@ -87,7 +87,7 @@ class TestPage(TestPageBase):
47 ]
48 )
49
50- @unittest.mock.patch("ubi-console-setup.gsettings.set_list")
51+ @unittest.mock.patch.object(ubi_console_setup.gsettings, "set_list")
52 def test_set_gnome_keyboard_layout_with_empty_input_sources(
53 self, set_list_mock
54 ):

Subscribers

People subscribed via source and target branches