Skip to content

Commit 9ce358e

Browse files
tests: fix pyside6 segfault in cmap combo tests (#319)
* tests: fix pyside6 segfault * style: [pre-commit.ci] auto fixes [...] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5335004 commit 9ce358e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tests/test_cmap.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,19 @@ def test_cmap_combo(qtbot, filterable):
101101
return # the rest fails on CI... but works locally
102102

103103
# click the Add Colormap... item
104+
# NOTE: We wrap __init__ instead of patching exec directly because
105+
# PySide6 6.10 crashes when MetaObjectBuilder inspects mocked methods
106+
# during signal connection (parsePythonType segfault)
107+
_original_init = _cmap_combo._CmapNameDialog.__init__
108+
109+
def _init_with_mock_exec(self, *args, **kwargs):
110+
_original_init(self, *args, **kwargs)
111+
self.exec = lambda: True
112+
104113
with qtbot.waitSignal(wdg.currentColormapChanged):
105-
with patch.object(_cmap_combo._CmapNameDialog, "exec", return_value=True):
114+
with patch.object(
115+
_cmap_combo._CmapNameDialog, "__init__", _init_with_mock_exec
116+
):
106117
wdg._on_activated(wdg.count() - 1)
107118

108119
assert wdg.count() == 5
@@ -111,7 +122,13 @@ def test_cmap_combo(qtbot, filterable):
111122
assert wdg.itemColormap(3).name.split(":")[-1] == "accent"
112123

113124
# click the Add Colormap... item, but cancel the dialog
114-
with patch.object(_cmap_combo._CmapNameDialog, "exec", return_value=False):
125+
def _init_with_mock_exec_false(self, *args, **kwargs):
126+
_original_init(self, *args, **kwargs)
127+
self.exec = lambda: False
128+
129+
with patch.object(
130+
_cmap_combo._CmapNameDialog, "__init__", _init_with_mock_exec_false
131+
):
115132
wdg._on_activated(wdg.count() - 1)
116133

117134

0 commit comments

Comments
 (0)